Skip to content

Commit b97f07a

Browse files
committed
only load MooseX::Getopt in script role
MooseX::Getopt is used in our scripts, and we need to tell it about some of the types we use. But that is only needed in the scripts. Rather than setting it up in the type module, we can set it up in the role that is used in every script. This means it won't be loaded in the web app.
1 parent 5e9831b commit b97f07a

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

lib/MetaCPAN/Role/Logger.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use Moose::Role;
66
use Log::Contextual qw( set_logger );
77
use Log::Log4perl ':easy';
88
use MetaCPAN::Types::TypeTiny qw( Logger Str );
9+
use MooseX::Getopt ();
910
use Path::Tiny qw( path );
1011

1112
has level => (

lib/MetaCPAN/Role/Script.pm

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@ use MooseX::Types::ElasticSearch qw( ES );
77
use IO::Prompt::Tiny qw( prompt );
88
use Log::Contextual qw( :log :dlog );
99
use MetaCPAN::Model ();
10-
use MetaCPAN::Types::TypeTiny qw( Bool HashRef Int Path Str );
10+
use MetaCPAN::Types::TypeTiny qw( AbsPath Bool HashRef Int Path Str );
1111
use MetaCPAN::Util qw( root_dir );
1212
use Mojo::Server ();
1313
use Term::ANSIColor qw( colored );
1414

15+
use MooseX::Getopt::OptionTypeMap ();
16+
for my $type ( Path, AbsPath ) {
17+
MooseX::Getopt::OptionTypeMap->add_option_type_to_map( $type, '=s' );
18+
}
19+
1520
with( 'MetaCPAN::Role::HasConfig', 'MetaCPAN::Role::Fastly',
1621
'MetaCPAN::Role::Logger' );
1722

lib/MetaCPAN/Types/TypeTiny.pm

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,6 @@ coerce HashRefCPANMeta, from InstanceOf ['CPAN::Meta'], via {
121121
return $struct ? $struct : $_->as_struct;
122122
};
123123

124-
# optionally add Getopt option type (adapted from MooseX::Types:Path::Class)
125-
if ( eval { require MooseX::Getopt; 1 } ) {
126-
for my $type ( Path, AbsPath ) {
127-
MooseX::Getopt::OptionTypeMap->add_option_type_to_map( $type, '=s' );
128-
}
129-
}
130-
131124
declare CommaSepOption, as ArrayRef [ StrMatch [qr{^[^, ]+$}] ];
132125
coerce CommaSepOption, from ArrayRef [Str], via {
133126
return [ map split(/\s*,\s*/), @$_ ];

0 commit comments

Comments
 (0)