From 3532e4fd7906f0e37ed89a7d00371169eef9ae27 Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Wed, 29 Jan 2025 05:27:21 +0100 Subject: [PATCH] use Type::Tiny for most types rather than built in Moose types --- lib/Catalyst/Authentication/Store/Proxy.pm | 4 ++-- lib/MetaCPAN/Model/Archive.pm | 4 ++-- lib/MetaCPAN/Model/Release.pm | 12 ++++++------ lib/MetaCPAN/Script/Snapshot.pm | 5 +++-- t/lib/MetaCPAN/Script/MockError.pm | 11 ++++++----- t/lib/MetaCPAN/Tests/Extra.pm | 3 ++- t/lib/MetaCPAN/Tests/Model.pm | 4 ++-- 7 files changed, 23 insertions(+), 20 deletions(-) diff --git a/lib/Catalyst/Authentication/Store/Proxy.pm b/lib/Catalyst/Authentication/Store/Proxy.pm index 47de4ad83..d941a60df 100644 --- a/lib/Catalyst/Authentication/Store/Proxy.pm +++ b/lib/Catalyst/Authentication/Store/Proxy.pm @@ -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', @@ -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 { diff --git a/lib/MetaCPAN/Model/Archive.pm b/lib/MetaCPAN/Model/Archive.pm index 60cb001d3..3ad4eebae 100644 --- a/lib/MetaCPAN/Model/Archive.pm +++ b/lib/MetaCPAN/Model/Archive.pm @@ -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 ); @@ -52,7 +52,7 @@ has file => ( has _extractor => ( is => 'ro', - isa => 'Archive::Any', + isa => InstanceOf ['Archive::Any'], handles => [ qw( is_impolite is_naughty diff --git a/lib/MetaCPAN/Model/Release.pm b/lib/MetaCPAN/Model/Release.pm index 3216ea733..f2e6a53c1 100644 --- a/lib/MetaCPAN/Model/Release.pm +++ b/lib/MetaCPAN/Model/Release.pm @@ -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; @@ -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', ); @@ -36,7 +36,7 @@ has dependencies => ( has distinfo => ( is => 'ro', - isa => 'CPAN::DistnameInfo', + isa => InstanceOf ['CPAN::DistnameInfo'], handles => { maturity => 'maturity', author => 'cpanid', @@ -53,7 +53,7 @@ has distinfo => ( has document => ( is => 'ro', - isa => 'MetaCPAN::Document::Release', + isa => InstanceOf ['MetaCPAN::Document::Release'], lazy => 1, builder => '_build_document', ); @@ -75,7 +75,7 @@ has files => ( has date => ( is => 'ro', - isa => 'DateTime', + isa => InstanceOf ['DateTime'], lazy => 1, default => sub { my $self = shift; @@ -87,7 +87,7 @@ has model => ( is => 'ro' ); has metadata => ( is => 'ro', - isa => 'CPAN::Meta', + isa => InstanceOf ['CPAN::Meta'], lazy => 1, builder => '_build_metadata', ); diff --git a/lib/MetaCPAN/Script/Snapshot.pm b/lib/MetaCPAN/Script/Snapshot.pm index cdcdf2081..dade43dc7 100644 --- a/lib/MetaCPAN/Script/Snapshot.pm +++ b/lib/MetaCPAN/Script/Snapshot.pm @@ -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 ); @@ -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; diff --git a/t/lib/MetaCPAN/Script/MockError.pm b/t/lib/MetaCPAN/Script/MockError.pm index e3ce317a9..67193e1b9 100644 --- a/t/lib/MetaCPAN/Script/MockError.pm +++ b/t/lib/MetaCPAN/Script/MockError.pm @@ -2,13 +2,14 @@ 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', ); @@ -16,7 +17,7 @@ has arg_error_message => ( has arg_error_code => ( init_arg => 'error', is => 'ro', - isa => 'Int', + isa => Int, default => -1, documentation => 'mock an Exit Code', ); @@ -24,7 +25,7 @@ has arg_error_code => ( has arg_die => ( init_arg => 'die', is => 'ro', - isa => 'Bool', + isa => Bool, default => 0, documentation => 'mock an Exception', ); @@ -32,7 +33,7 @@ has arg_die => ( has arg_handle_error => ( init_arg => 'handle_error', is => 'ro', - isa => 'Bool', + isa => Bool, default => 0, documentation => 'mock a handled error', ); @@ -40,7 +41,7 @@ has arg_handle_error => ( has arg_exception => ( init_arg => 'exception', is => 'ro', - isa => 'Bool', + isa => Bool, default => 0, documentation => 'mock an Exception Class', ); diff --git a/t/lib/MetaCPAN/Tests/Extra.pm b/t/lib/MetaCPAN/Tests/Extra.pm index 5863dd13b..25918810d 100644 --- a/t/lib/MetaCPAN/Tests/Extra.pm +++ b/t/lib/MetaCPAN/Tests/Extra.pm @@ -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', ); diff --git a/t/lib/MetaCPAN/Tests/Model.pm b/t/lib/MetaCPAN/Tests/Model.pm index 1a9f8e799..b21e85d8a 100644 --- a/t/lib/MetaCPAN/Tests/Model.pm +++ b/t/lib/MetaCPAN/Tests/Model.pm @@ -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 ); @@ -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() }, );