Skip to content

Commit

Permalink
use Type::Tiny for most types rather than built in Moose types
Browse files Browse the repository at this point in the history
  • Loading branch information
haarg committed Jan 29, 2025
1 parent d593825 commit 3532e4f
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 20 deletions.
4 changes: 2 additions & 2 deletions lib/Catalyst/Authentication/Store/Proxy.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package Catalyst::Authentication::Store::Proxy;
# ABSTRACT: Delegates authentication logic to the user object
use Moose;
use Catalyst::Utils ();
use MetaCPAN::Types::TypeTiny qw( HashRef Str );
use MetaCPAN::Types::TypeTiny qw( ClassName HashRef Str );

has user_class => (
is => 'ro',
Expand All @@ -14,7 +14,7 @@ has user_class => (
);
has handles => ( is => 'ro', isa => HashRef );
has config => ( is => 'ro', isa => HashRef );
has app => ( is => 'ro', isa => 'ClassName' );
has app => ( is => 'ro', isa => ClassName );
has realm => ( is => 'ro' );

sub BUILDARGS {
Expand Down
4 changes: 2 additions & 2 deletions lib/MetaCPAN/Model/Archive.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package MetaCPAN::Model::Archive;
use v5.10;
use Moose;
use MooseX::StrictConstructor;
use MetaCPAN::Types::TypeTiny qw( AbsPath ArrayRef Bool Str );
use MetaCPAN::Types::TypeTiny qw( AbsPath ArrayRef Bool InstanceOf Str );

use Archive::Any ();
use Carp qw( croak );
Expand Down Expand Up @@ -52,7 +52,7 @@ has file => (

has _extractor => (
is => 'ro',
isa => 'Archive::Any',
isa => InstanceOf ['Archive::Any'],
handles => [ qw(
is_impolite
is_naughty
Expand Down
12 changes: 6 additions & 6 deletions lib/MetaCPAN/Model/Release.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use File::Spec ();
use Log::Contextual qw( :log :dlog );
use MetaCPAN::ESConfig qw( es_doc_path );
use MetaCPAN::Model::Archive ();
use MetaCPAN::Types::TypeTiny qw( AbsPath ArrayRef Str );
use MetaCPAN::Types::TypeTiny qw( AbsPath ArrayRef InstanceOf Str );
use MetaCPAN::Util qw( fix_version true false );
use Module::Metadata 1.000012 (); # Improved package detection.
use MooseX::StrictConstructor;
Expand All @@ -22,7 +22,7 @@ use Try::Tiny qw( catch try );

has archive => (
is => 'ro',
isa => 'MetaCPAN::Model::Archive',
isa => InstanceOf ['MetaCPAN::Model::Archive'],
lazy => 1,
builder => '_build_archive',
);
Expand All @@ -36,7 +36,7 @@ has dependencies => (

has distinfo => (
is => 'ro',
isa => 'CPAN::DistnameInfo',
isa => InstanceOf ['CPAN::DistnameInfo'],
handles => {
maturity => 'maturity',
author => 'cpanid',
Expand All @@ -53,7 +53,7 @@ has distinfo => (

has document => (
is => 'ro',
isa => 'MetaCPAN::Document::Release',
isa => InstanceOf ['MetaCPAN::Document::Release'],
lazy => 1,
builder => '_build_document',
);
Expand All @@ -75,7 +75,7 @@ has files => (

has date => (
is => 'ro',
isa => 'DateTime',
isa => InstanceOf ['DateTime'],
lazy => 1,
default => sub {
my $self = shift;
Expand All @@ -87,7 +87,7 @@ has model => ( is => 'ro' );

has metadata => (
is => 'ro',
isa => 'CPAN::Meta',
isa => InstanceOf ['CPAN::Meta'],
lazy => 1,
builder => '_build_metadata',
);
Expand Down
5 changes: 3 additions & 2 deletions lib/MetaCPAN/Script/Snapshot.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use DateTime::Format::ISO8601 ();
use HTTP::Tiny ();
use Log::Contextual qw( :log :dlog );
use MetaCPAN::Server::Config ();
use MetaCPAN::Types::TypeTiny qw( ArrayRef Bool Str );
use MetaCPAN::Types::TypeTiny qw( ArrayRef Bool Str Uri );
use Moose;
use Sys::Hostname qw( hostname );

Expand Down Expand Up @@ -81,7 +81,8 @@ has snap_name => (

has host => (
is => 'ro',
isa => 'URI::http',
isa => Uri,
coerce => 1,
default => sub {
my $self = shift;
return $self->es->transport->cxn_pool->cxns->[0]->uri;
Expand Down
11 changes: 6 additions & 5 deletions t/lib/MetaCPAN/Script/MockError.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,46 @@ package MetaCPAN::Script::MockError;

use Moose;
use Exception::Class ('MockException');
use MetaCPAN::Types::TypeTiny qw( Bool Int Str );

with 'MetaCPAN::Role::Script', 'MooseX::Getopt';

has arg_error_message => (
init_arg => 'message',
is => 'ro',
isa => 'Str',
isa => Str,
default => "",
documentation => 'mock an Error Message',
);

has arg_error_code => (
init_arg => 'error',
is => 'ro',
isa => 'Int',
isa => Int,
default => -1,
documentation => 'mock an Exit Code',
);

has arg_die => (
init_arg => 'die',
is => 'ro',
isa => 'Bool',
isa => Bool,
default => 0,
documentation => 'mock an Exception',
);

has arg_handle_error => (
init_arg => 'handle_error',
is => 'ro',
isa => 'Bool',
isa => Bool,
default => 0,
documentation => 'mock a handled error',
);

has arg_exception => (
init_arg => 'exception',
is => 'ro',
isa => 'Bool',
isa => Bool,
default => 0,
documentation => 'mock an Exception Class',
);
Expand Down
3 changes: 2 additions & 1 deletion t/lib/MetaCPAN/Tests/Extra.pm
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package MetaCPAN::Tests::Extra;
use Test::More;
use Test::Routine;
use MetaCPAN::Types::TypeTiny qw( CodeRef );

has _extra_tests => (
is => 'ro',
isa => 'CodeRef',
isa => CodeRef,
init_arg => 'extra_tests',
predicate => 'has_extra_tests',
);
Expand Down
4 changes: 2 additions & 2 deletions t/lib/MetaCPAN/Tests/Model.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package MetaCPAN::Tests::Model;
use Test::Routine;

use MetaCPAN::Server::Test ();
use MetaCPAN::Types::TypeTiny qw( ArrayRef HashRef Str );
use MetaCPAN::Types::TypeTiny qw( ArrayRef HashRef InstanceOf Str );
use Test::More;
use Try::Tiny qw( try );

Expand Down Expand Up @@ -42,7 +42,7 @@ has _type => (

has model => (
is => 'ro',
isa => 'MetaCPAN::Model',
isa => InstanceOf ['MetaCPAN::Model'],
lazy => 1,
default => sub { MetaCPAN::Server::Test::model() },
);
Expand Down

0 comments on commit 3532e4f

Please sign in to comment.