From: Piotr Roszatycki Date: Thu, 13 Nov 2008 14:07:49 +0000 (+0000) Subject: * MooseX::Getopt: ARGV and extra_argv are deletaged from MooseX::Getopt::Session. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ac2073c861c686a00941f7b6d5c9c1b4013d7671;p=gitmo%2FMooseX-Getopt.git * MooseX::Getopt: ARGV and extra_argv are deletaged from MooseX::Getopt::Session. * MooseX::Getopt::Parser::Default: Factory which returns default MooseX::Getopt::Parser. * MooseX::Getopt::OptionTypeMap: Call Moose->throw_error for errors. * t/*.t: Test units for MooseX::Getopt::Parser::Default. * All code reformated. --- diff --git a/ChangeLog b/ChangeLog index 75d2a43..3b8ca54 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,7 @@ Revision history for Perl extension MooseX-Getopt 0.150001 ??? * MooseX::Getopt + * MooseX::Getopt::OptionTypeMap - Use Moose's throw_error() method. (dexter) * MooseX::Getopt @@ -10,6 +11,7 @@ Revision history for Perl extension MooseX-Getopt (dexter) * MooseX::Getopt::Parser + * MooseX::Getopt::Parser::Default * MooseX::Getopt::Parser::Long * MooseX::Getopt::Parser::Descriptive - Getopt parser is pluggined. @@ -17,8 +19,6 @@ Revision history for Perl extension MooseX-Getopt * TODO: - MooseX::ConfigFromFile should be restored? - - POD. - - New test units. 0.15 Sat. July 26 2008 * MooseX::Getopt::OptionTypeMap diff --git a/MANIFEST b/MANIFEST index 1f11768..b048d79 100644 --- a/MANIFEST +++ b/MANIFEST @@ -17,6 +17,7 @@ lib/MooseX/Getopt/Meta/Attribute/Trait.pm lib/MooseX/Getopt/Meta/Attribute/Trait/NoGetopt.pm lib/MooseX/Getopt/OptionTypeMap.pm lib/MooseX/Getopt/Parser.pm +lib/MooseX/Getopt/Parser/Default.pm lib/MooseX/Getopt/Parser/Descriptive.pm lib/MooseX/Getopt/Parser/Long.pm lib/MooseX/Getopt/Session.pm diff --git a/lib/MooseX/Getopt.pm b/lib/MooseX/Getopt.pm index 48ea79e..8bc9399 100644 --- a/lib/MooseX/Getopt.pm +++ b/lib/MooseX/Getopt.pm @@ -19,22 +19,11 @@ our $AUTHORITY = 'cpan:STEVAN'; use constant _default_getopt_session => 'MooseX::Getopt::Session'; -has ARGV => ( - is => 'rw', - isa => 'ArrayRef', - metaclass => 'NoGetopt', -); - -has extra_argv => ( - is => 'rw', - isa => 'ArrayRef', - metaclass => 'NoGetopt', -); - has getopt => ( is => 'rw', isa => 'MooseX::Getopt::Session', metaclass => 'NoGetopt', + handles => [ 'ARGV', 'extra_argv' ], ); @@ -49,19 +38,15 @@ sub new_with_options { my $getopt = defined $params{getopt} ? $params{getopt} : $class->_default_getopt_session->new( - classes_filter => sub { $_ eq $class }, - params => \%params, - ); - - my %options = $getopt->options; + classes_filter => sub { $_ eq $class }, + params => \%params, + ); $class->new( - ARGV => [ $getopt->argv ], # backward compatibility - extra_argv => [ $getopt->extra_argv ], # backward compatibility getopt => $getopt, %{ $getopt->params }, # params from session object %params, # explicit params to ->new - %options, # params from CLI + %{ $getopt->options }, # params from CLI ); }; @@ -262,6 +247,42 @@ type for it to the C, it would be treated just like a normal C type for Getopt purposes (that is, C<=s@>). +=head2 Session + +L can handle more than one class which contain +attributes filled from CLI. In this case, you need to use explicite +L object and then the Getopt attributes will be +searched in any class which does L. + + package My::App; + use Moose; + with 'MooseX::Getopt'; + has 'send' => (is => 'rw', predicate => 'has_send'); + + package My::App::Send; + use Moose; + with 'MooseX::Getopt'; + has 'to' => (is => 'rw', isa => 'Str', default => 'localhost'); + sub send { my $self = shift; warn "Sending mail to ", $self->to; } + + # ... rest of the class here + + ## in your script + #!/usr/bin/perl + + my $getopt = MooseX::Getopt::Session->new; + + my $app = My::App->new_with_options( getopt => $getopt ); + if ($app->has_send) { + # Use the same command line + my $sender = My::App::Send->new_with_options( getopt => $getopt ); + $sender->send; + } + # ... rest of the script here + + ## on the command line + % perl my_app_script.pl --send --to server.example.net + =head1 METHODS =over 4 @@ -280,8 +301,10 @@ C. =item B -This accessor contains a reference to a copy of the C<@ARGV> array -as it originally existed at the time of C. +This accessor contains a reference to a copy of the C<@ARGV> array as it +originally existed at the time of C. + +The C is delegated from L object. =item B @@ -289,12 +312,32 @@ This accessor contains an arrayref of leftover C<@ARGV> elements that L did not parse. Note that the real C<@ARGV> is left un-mangled. +The C is delegated from L object. + +=item B + +This accessor contains a L object. This object can +be shared between more than one class which does L. The new +object is created by default. + =item B This returns the role meta object. =back +=head1 SEE ALSO + +=over 4 + +=item L + +=item L + +=item L + +=back + =head1 BUGS All complex software has bugs lurking in it, and this module is no @@ -313,6 +356,8 @@ Yuval Kogman, Enothingmuch@woobling.orgE Ryan D Johnson, Eryan@innerfence.comE +Piotr Roszatycki, Edexter@cpan.orgE + =head1 COPYRIGHT AND LICENSE Copyright 2007-2008 by Infinity Interactive, Inc. diff --git a/lib/MooseX/Getopt/OptionTypeMap.pm b/lib/MooseX/Getopt/OptionTypeMap.pm index 3ec2832..63bd3ba 100644 --- a/lib/MooseX/Getopt/OptionTypeMap.pm +++ b/lib/MooseX/Getopt/OptionTypeMap.pm @@ -13,7 +13,7 @@ my %option_type_map = ( 'Int' => '=i', 'Num' => '=f', 'ArrayRef' => '=s@', - 'HashRef' => '=s%', + 'HashRef' => '=s%', ); sub has_option_type { @@ -22,10 +22,10 @@ sub has_option_type { return 1 if exists $option_type_map{blessed($type_or_name) ? $type_or_name->name : $type_or_name}; my $current = blessed($type_or_name) ? $type_or_name : find_type_constraint($type_or_name); - + (defined $current) - || confess "Could not find the type constraint for '$type_or_name'"; - + || Moose->throw_error("Could not find the type constraint for '$type_or_name'"); + while (my $parent = $current->parent) { return 1 if exists $option_type_map{$parent->name}; $current = $parent; @@ -42,9 +42,9 @@ sub get_option_type { return $option_type_map{$name} if exists $option_type_map{$name}; my $current = ref $type_or_name ? $type_or_name : find_type_constraint($type_or_name); - + (defined $current) - || confess "Could not find the type constraint for '$type_or_name'"; + || Moose->throw_error("Could not find the type constraint for '$type_or_name'"); while ( $current = $current->parent ) { return $option_type_map{$current->name} @@ -57,13 +57,13 @@ sub get_option_type { sub add_option_type_to_map { my (undef, $type_name, $option_string) = @_; (defined $type_name && defined $option_string) - || confess "You must supply both a type name and an option string"; + || Moose->throw_error("You must supply both a type name and an option string"); if ( blessed($type_name) ) { $type_name = $type_name->name; } else { (find_type_constraint($type_name)) - || confess "The type constraint '$type_name' does not exist"; + || Moose->throw_error("The type constraint '$type_name' does not exist"); } $option_type_map{$type_name} = $option_string; @@ -103,7 +103,7 @@ These are all class methods and should be called as such. =head1 BUGS -All complex software has bugs lurking in it, and this module is no +All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT. diff --git a/lib/MooseX/Getopt/Parser.pm b/lib/MooseX/Getopt/Parser.pm index 945d113..e066feb 100644 --- a/lib/MooseX/Getopt/Parser.pm +++ b/lib/MooseX/Getopt/Parser.pm @@ -5,3 +5,71 @@ use Moose::Role; requires 'build_options'; 1; + +__END__ + +=pod + +=head1 NAME + +MooseX::Getopt::Parser - A Moose role for MooseX::Getopt's parser + +=head1 SYNOPSIS + + package MooseX::Getopt::Parser::Descriptive; + use Moose; + with 'MooseX::Getopt::Parser'; + sub build_options { + my $self = shift; + my ($getopt, @attrs) = @_; + Moose->throw_error('First argument is not a MooseX::Getopt::Session') + unless $getopt->isa('MooseX::Getopt::Session'); + + my $options = {}; + + # your code is here + + return $options; + } + +=head1 DESCRIPTION + +This is a L role for L's parser. The parser have +to implement C method which takes a +L object and attributes list which will be +filled by parser. + +=head1 BUGS + +All complex software has bugs lurking in it, and this module is no +exception. If you find a bug please either email me, or add the bug +to cpan-RT. + +=head1 SEE ALSO + +=over 4 + +=item L + +=item L + +=item L + +=item L + +=back + +=head1 AUTHOR + +Piotr Roszatycki, Edexter@cpan.orgE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2007-2008 by Infinity Interactive, Inc. + +L + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut diff --git a/lib/MooseX/Getopt/Parser/Default.pm b/lib/MooseX/Getopt/Parser/Default.pm new file mode 100644 index 0000000..8c460c4 --- /dev/null +++ b/lib/MooseX/Getopt/Parser/Default.pm @@ -0,0 +1,85 @@ + +package MooseX::Getopt::Parser::Default; + +use Moose; + +use MooseX::Getopt::Parser::Long; +use maybe 'MooseX::Getopt::Parser::Descriptive'; + + +sub new { + my $class = shift; + return maybe::HAVE_MOOSEX_GETOPT_PARSER_DESCRIPTIVE + ? MooseX::Getopt::Parser::Descriptive->new(@_) + : MooseX::Getopt::Parser::Long->new(@_); +}; + + +1; + +__END__ + +=pod + +=head1 NAME + +MooseX::Getopt::Parser::Default - A default parser for MooseX::Getopt + +=head1 SYNOPSIS + + use MooseX::Getopt::Parser::Default; + + my $parser = MooseX::Getopt::Parser::Default->new( config => ['pass_through'] ); + my $getopt = MooseX::Getopt::Session->new( parser => $parser ); + my $app = My::App->new( getopt => $getopt ); + +=head1 DESCRIPTION + +This class contains the factory method which returns new +L object. The object's class is +L if L +module exists or L otherwise. + +=head1 METHODS + +=over 4 + +=item B + +This is the factory method which returns new L +object. All C<%params> are passed to new object. + +=back + +=head1 BUGS + +All complex software has bugs lurking in it, and this module is no +exception. If you find a bug please either email me, or add the bug +to cpan-RT. + +=head1 SEE ALSO + +=over 4 + +=item L + +=item L + +=item L + +=back + +=head1 AUTHOR + +Piotr Roszatycki, Edexter@cpan.orgE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2007-2008 by Infinity Interactive, Inc. + +L + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut diff --git a/lib/MooseX/Getopt/Parser/Descriptive.pm b/lib/MooseX/Getopt/Parser/Descriptive.pm index 3e71d34..c60839c 100644 --- a/lib/MooseX/Getopt/Parser/Descriptive.pm +++ b/lib/MooseX/Getopt/Parser/Descriptive.pm @@ -8,10 +8,9 @@ with 'MooseX::Getopt::Parser'; use Getopt::Long::Descriptive; use MooseX::Getopt::OptionTypeMap; -#use Smart::Comments; # Special configuration for parser -has 'config' => ( +has config => ( is => 'rw', isa => 'ArrayRef[Str]', auto_deref => 1, @@ -19,7 +18,7 @@ has 'config' => ( ); # Format for usage description -has 'format' => ( +has format => ( is => 'rw', isa => 'Str', default => 'usage: %c %o', @@ -43,7 +42,7 @@ sub build_options { my ($flag, @aliases) = $getopt->_get_cmd_flags_for_attr($attr); my $type = $getopt->_get_cmd_type_for_attr($attr); - $cmd_flags_to_names{$flag} = $name; + $cmd_flags_to_names{$flag} = $name; my $opt_string = join '|', $flag, @aliases; $opt_string .= MooseX::Getopt::OptionTypeMap->get_option_type($type) if $type; @@ -65,15 +64,14 @@ sub build_options { ]; }; - ### MooseX::Getopt::Parser::Descriptive::build_options @opts : @opts + my $warnings = ''; GETOPT: { - local @ARGV = $getopt->argv; - ### MooseX::Getopt::Parser::Descriptive::build_options @ARGV : @ARGV + local @ARGV = @{ $getopt->ARGV }; local $SIG{__WARN__} = sub { return warn @_ if $_[0]=~/^\###/; # Smart::Comments - $getopt->strcat_warning( $_[0] ) + $warnings .= $_[0]; }; eval { @@ -82,31 +80,104 @@ sub build_options { ); }; my $e = $@; - $getopt->strcat_warning( $e ) if $e; - $getopt->status( ! $e ); + $warnings .= $e if $e; my $extra_argv = \@ARGV; $getopt->extra_argv( $extra_argv ); }; # Convert cmd_flags back to names in options hashref - $options = { - map { - $cmd_flags_to_names{$_} => $options->{$_} - } keys %$options, - }; + $options = { map { $cmd_flags_to_names{$_} => $options->{$_} } keys %$options }; - #%options = map { $_ => $options{$_} } grep { defined $options{$_} } keys %options; $getopt->options( $options ); - ### MooseX::Getopt::Parser::Descriptive::build_options $options : $options - ### MooseX::Getopt::Parser::Descriptive::build_options $usage : $usage - ### MooseX::Getopt::Parser::Descriptive::build_options $getopt->status : $getopt->status - - die join '', $getopt->warning if ($getopt->has_warning || !$getopt->status); + die $warnings if $warnings; return $options; }; 1; + +__END__ + +=pod + +=head1 NAME + +MooseX::Getopt::Parser::Descriptive - A Getopt::Long::Descriptive parser for MooseX::Getopt + +=head1 SYNOPSIS + + use MooseX::Getopt::Parser::Descriptive; + + my $parser = MooseX::Getopt::Parser::Descriptive->new( + format => 'Usage: %c %o', + config => ['pass_through'] + ); + my $getopt = MooseX::Getopt::Session->new( parser => $parser ); + my $app = My::App->new( getopt => $getopt ); + +=head1 DESCRIPTION + +This class does L for L. This +class is used by default if L module is +missing. + +=head1 METHODS + +=over 4 + +=item B + +This method parses the CLI options with L and returns a hashref to options list. + +The first argument have to be L object and +second argument is a list of attributes which contains options. + +=item B + +This accessor contains the arrayref to list with special configuration +keywords for L. + +=item B + +This accessor contains the string with message printed by +L if error is occured. + +=back + +=head1 BUGS + +All complex software has bugs lurking in it, and this module is no +exception. If you find a bug please either email me, or add the bug +to cpan-RT. + +=head1 SEE ALSO + +=over 4 + +=item L + +=item L + +=item L + +=item L + +=back + +=head1 AUTHOR + +Piotr Roszatycki, Edexter@cpan.orgE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2007-2008 by Infinity Interactive, Inc. + +L + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut diff --git a/lib/MooseX/Getopt/Parser/Long.pm b/lib/MooseX/Getopt/Parser/Long.pm index e7c5828..d676e1b 100644 --- a/lib/MooseX/Getopt/Parser/Long.pm +++ b/lib/MooseX/Getopt/Parser/Long.pm @@ -8,10 +8,9 @@ with 'MooseX::Getopt::Parser'; use Getopt::Long; use MooseX::Getopt::OptionTypeMap; -#use Smart::Comments; # Special configuration for parser -has 'config' => ( +has config => ( is => 'rw', isa => 'ArrayRef[Str]', auto_deref => 1, @@ -26,7 +25,7 @@ sub build_options { Moose->throw_error('First argument is not a MooseX::Getopt::Session') unless $getopt->isa('MooseX::Getopt::Session'); - my %options; + my $options = {}; my @opts; foreach my $attr (@attrs) { @@ -38,39 +37,113 @@ sub build_options { my $opt_string = join '|', $flag, @aliases; $opt_string .= MooseX::Getopt::OptionTypeMap->get_option_type($type) if $type; - $options{$name} = undef; - push @opts, $opt_string => \$options{$name}; + $options->{$name} = undef; + push @opts, $opt_string => \$options->{$name}; }; - ### MooseX::Getopt::Parser::Long::build_options @opts : @opts + my $warnings = ''; GETOPT: { my $parser = new Getopt::Long::Parser; $parser->configure( $self->config ); - local @ARGV = $getopt->argv; - ### MooseX::Getopt::Parser::Long::build_options @ARGV : @ARGV + local @ARGV = @{ $getopt->ARGV }; local $SIG{__WARN__} = sub { return warn @_ if $_[0]=~/^\###/; # Smart::Comments - $getopt->strcat_warning( $_[0] ) + $warnings .= $_[0]; }; - my $status = $parser->getoptions( @opts ); - $getopt->status( $status ); + $parser->getoptions( @opts ); my $extra_argv = \@ARGV; $getopt->extra_argv( $extra_argv ); }; - %options = map { $_ => $options{$_} } grep { defined $options{$_} } keys %options; - $getopt->options( \%options ); + # Filter not defined values in options hashref + $options = { map { $_ => $options->{$_} } grep { defined $options->{$_} } keys %$options }; - die join '', $getopt->warning if $getopt->has_warning; + $getopt->options( $options ); - ### MooseX::Getopt::Parser::Long::build_options %options : %options - return \%options; + die $warnings if $warnings; + + return $options; }; 1; + +__END__ + +=pod + +=head1 NAME + +MooseX::Getopt::Parser::Long - A Getopt::Long parser for MooseX::Getopt + +=head1 SYNOPSIS + + use MooseX::Getopt::Parser::Long; + + my $parser = MooseX::Getopt::Parser::Long->new( config => ['pass_through'] ); + my $getopt = MooseX::Getopt::Session->new( parser => $parser ); + my $app = My::App->new( getopt => $getopt ); + +=head1 DESCRIPTION + +This class does L for L. This +class is used by default if L module is +missing. + +=head1 METHODS + +=over 4 + +=item B + +This method parses the CLI options with L and returns a hashref to options list. + +The first argument have to be L object and +second argument is a list of attributes which contains options. + +=item B + +This accessor contains the arrayref to list with special configuration +keywords for L. + +=back + +=head1 BUGS + +All complex software has bugs lurking in it, and this module is no +exception. If you find a bug please either email me, or add the bug +to cpan-RT. + +=head1 SEE ALSO + +=over 4 + +=item L + +=item L + +=item L + +=item L + +=back + +=head1 AUTHOR + +Piotr Roszatycki, Edexter@cpan.orgE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2007-2008 by Infinity Interactive, Inc. + +L + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut diff --git a/lib/MooseX/Getopt/Session.pm b/lib/MooseX/Getopt/Session.pm index 60f496c..3359f9a 100644 --- a/lib/MooseX/Getopt/Session.pm +++ b/lib/MooseX/Getopt/Session.pm @@ -3,76 +3,56 @@ package MooseX::Getopt::Session; use Moose; -use MooseX::Getopt::Parser::Long; -use maybe 'MooseX::Getopt::Parser::Descriptive'; +use MooseX::Getopt::Parser::Default; + + +use constant _default_getopt_parser => 'MooseX::Getopt::Parser::Default'; -#use Smart::Comments; # Pluggined MooseX::Getopt::Parser parser -has 'parser' => ( +has parser => ( is => 'rw', does => 'MooseX::Getopt::Parser', - default => sub { - maybe::HAVE_MOOSEX_GETOPT_PARSER_DESCRIPTIVE - ? MooseX::Getopt::Parser::Descriptive->new - : MooseX::Getopt::Parser::Long->new - }, + default => sub { $_[0]->_default_getopt_parser->new }, ); # Filter for classes which are searched for getopt trait -has 'classes_filter' => ( +has classes_filter => ( is => 'rw', isa => 'CodeRef', default => sub { sub { 1 } }, ); # Explicite parameters for new_with_options -has 'params' => ( +has params => ( is => 'rw', isa => 'HashRef', default => sub { {} }, ); # Original @ARGV values -has 'argv' => ( +has ARGV => ( is => 'rw', isa => 'ArrayRef[Str]', - auto_deref => 1, default => sub { [ @ARGV ] }, ); # Unrecognized @ARGV values -has 'extra_argv' => ( +has extra_argv => ( is => 'rw', isa => 'ArrayRef[Str]', - auto_deref => 1, default => sub { [] }, ); # Hash with options parsed from argv -has 'options' => ( +has options => ( is => 'rw', isa => 'HashRef', - auto_deref => 1, default => sub { {} }, ); -# Status of parser -has 'status' => ( - is => 'rw', - isa => 'Bool', -); - -# Warnings collected by parser -has 'warning' => ( - is => 'rw', - isa => 'Str', - predicate => 'has_warning', -); -# Die if warnings was occured sub BUILD { - ### MooseX::Getopt::Session::BUILD : @_ my ($self, $args) = @_; $self->build_options; @@ -83,7 +63,6 @@ sub build_options { my ($self) = @_; my @attrs = map { $_->_compute_getopt_attrs } $self->_compute_getopt_classes; - ### MooseX::Getopt::Session::build_options @attrs -> name : map { $_->name } @attrs return $self->parser->build_options( $self, @attrs ); } @@ -120,7 +99,7 @@ sub _get_cmd_type_for_attr { my ($self, $attr) = @_; my $type; - + $type = $attr->type_constraint if $attr->has_type_constraint; if ($attr->does('MooseX::Getopt::Meta::Attribute::Trait')) { @@ -131,11 +110,135 @@ sub _get_cmd_type_for_attr { }; -sub strcat_warning { - my ($self, $string) = @_; +1; - return $self->warning( ($self->has_warning ? $self->warning : '') . $string ); -}; +__END__ +=pod -1; +=head1 NAME + +MooseX::Getopt::Session - A CLI session for MooseX::Getopt + +=head1 SYNOPSIS + + ## in your script + #!/usr/bin/perl + + use My::App; + + my $getopt = MooseX::Getopt::Session->new; + + my $app = My::App->new_with_options( getopt => $getopt ); + my $cmd = My::App::Cmd->new_with_options( getopt => $getopt ); + +=head1 DESCRIPTION + +This class handles CLI session for L. The session can +be shared between more than one classes which does L. +If C parameter is missing, new session is created for one class. + +The L scans all classes and gets these which do +L. These classes will make an option list for +L. + +=head1 METHODS + +=over 4 + +=item B + +This method creates new CLI session for L and calls +C method. + +=item B + +This method creates the list of attributes which contains options and +calls C method from L with this +object and attributes list as parameters. + +=item B + +This accessor contains a parser object which does +L. It can be set explicite, i.e. if you need to +modify the way parser works, or new object via +L factory will be created. + +=item B + +This accessor contains a coderef with classes filter which is used for +searching proper classes to create options list. The filter passes any +class by default but L will search the attributes only +in own class, if new session is created implicity. + +=item B + +This accessor contains the parameters which will be included to each +L->new_with_options call. + +=item B + +This accessor contains a reference to a copy of the C<@ARGV> array as it +originally existed at the time of C. + +=item B + +This accessor contains an arrayref of leftover C<@ARGV> elements that +L did not parse. Note that the real C<@ARGV> is left +un-mangled. + +=item B + +This accessor contains an arrayref of options parsed from command line +by L. + +=item B + +This is a default L constructor. + +=item B + +This returns the role meta object. + +=back + +=head1 SEE ALSO + +=over 4 + +=item L + +=item L + +=back + +=head1 BUGS + +All complex software has bugs lurking in it, and this module is no +exception. If you find a bug please either email me, or add the bug +to cpan-RT. + +=head1 AUTHOR + +Stevan Little Estevan@iinteractive.comE + +Brandon L. Black, Eblblack@gmail.comE + +Yuval Kogman, Enothingmuch@woobling.orgE + +=head1 CONTRIBUTORS + +Ryan D Johnson, Eryan@innerfence.comE + +Piotr Roszatycki, Edexter@cpan.orgE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2007-2008 by Infinity Interactive, Inc. + +L + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut diff --git a/lib/MooseX/Getopt/Strict.pm b/lib/MooseX/Getopt/Strict.pm index 3c9ef39..266ebf4 100644 --- a/lib/MooseX/Getopt/Strict.pm +++ b/lib/MooseX/Getopt/Strict.pm @@ -7,9 +7,9 @@ with 'MooseX::Getopt'; around '_compute_getopt_attrs' => sub { my $next = shift; my ($class, @args) = @_; - - return grep { - $_->does('MooseX::Getopt::Meta::Attribute::Trait') + + return grep { + $_->does('MooseX::Getopt::Meta::Attribute::Trait') } $class->$next(@args); }; @@ -22,13 +22,13 @@ __END__ =head1 NAME MooseX::Getopt::Strict - only make options for attrs with the Getopt metaclass - + =head1 DESCRIPTION -This is an stricter version of C which only processes the +This is an stricter version of C which only processes the attributes if they explicitly set as C attributes. All other attributes are ignored by the command line handler. - + =head1 METHODS =over 4 @@ -37,9 +37,17 @@ are ignored by the command line handler. =back +=head1 SEE ALSO + +=over 4 + +=item L + +=back + =head1 BUGS -All complex software has bugs lurking in it, and this module is no +All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT. diff --git a/t/001_basic.t b/t/001_basic.t index 48dca21..2d92593 100644 --- a/t/001_basic.t +++ b/t/001_basic.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 185; +use Test::More tests => 263; BEGIN { use_ok('MooseX::Getopt'); @@ -87,7 +87,7 @@ foreach my $attr_name (qw(data cow horse _private_stuff_cmdline)) { can_ok($attr, 'cmd_aliases'); } -foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser::Descriptive)) { +foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser::Descriptive MooseX::Getopt::Parser::Default)) { SKIP: { if ($parser_name eq 'MooseX::Getopt::Parser::Descriptive') { eval { require Getopt::Long::Descriptive }; @@ -98,7 +98,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = (); my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); @@ -117,7 +117,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = ('--verbose', '--length', 50); my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); @@ -136,7 +136,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = ('--verbose', '-f', 'foo.txt'); my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); @@ -156,7 +156,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = ('--verbose', '--libs', 'libs/', '--libs', 'includes/lib'); my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); @@ -177,7 +177,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = ('--details', 'os=mac', '--details', 'name=foo'); my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); @@ -199,7 +199,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = ('--noverbose'); my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); @@ -219,7 +219,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = ('--cow', '42'); my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); @@ -232,7 +232,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = ('--moocow', '88'); my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); @@ -245,7 +245,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = ('-c', '99'); my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); @@ -260,7 +260,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = ('--horsey', '123'); my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); @@ -273,7 +273,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = ('-x', '321'); my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); @@ -288,7 +288,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = ('-p', '666'); my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); @@ -305,7 +305,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = @args; my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); diff --git a/t/002_custom_option_type.t b/t/002_custom_option_type.t index 3ccdc7e..ce4f9b8 100644 --- a/t/002_custom_option_type.t +++ b/t/002_custom_option_type.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 21; +use Test::More tests => 31; BEGIN { use_ok('MooseX::Getopt'); @@ -34,7 +34,7 @@ BEGIN { } -foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser::Descriptive)) { +foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser::Descriptive MooseX::Getopt::Parser::Default)) { SKIP: { if ($parser_name eq 'MooseX::Getopt::Parser::Descriptive') { eval { require Getopt::Long::Descriptive }; @@ -45,7 +45,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = (); my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); @@ -60,7 +60,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = ('--nums', 3, '--nums', 5); my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); @@ -78,7 +78,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = ('--nums', 3, '--nums', 'foo'); my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); diff --git a/t/003_inferred_option_type.t b/t/003_inferred_option_type.t index 4581bc8..065a1c6 100644 --- a/t/003_inferred_option_type.t +++ b/t/003_inferred_option_type.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 17; +use Test::More tests => 25; BEGIN { use_ok('MooseX::Getopt'); @@ -30,7 +30,7 @@ BEGIN { } -foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser::Descriptive)) { +foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser::Descriptive MooseX::Getopt::Parser::Default)) { SKIP: { if ($parser_name eq 'MooseX::Getopt::Parser::Descriptive') { eval { require Getopt::Long::Descriptive }; @@ -41,7 +41,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = (); my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); @@ -56,7 +56,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = ('--nums', 3, '--nums', 5); my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); diff --git a/t/004_nogetop.t b/t/004_nogetop.t index e4a1c5a..89977d0 100644 --- a/t/004_nogetop.t +++ b/t/004_nogetop.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 23; +use Test::More tests => 34; use Test::Exception; BEGIN { @@ -81,7 +81,7 @@ BEGIN { } -foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser::Descriptive)) { +foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser::Descriptive MooseX::Getopt::Parser::Default)) { SKIP: { if ($parser_name eq 'MooseX::Getopt::Parser::Descriptive') { eval { require Getopt::Long::Descriptive }; @@ -92,7 +92,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = (); my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); @@ -113,7 +113,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: throws_ok { my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); diff --git a/t/005_strict.t b/t/005_strict.t index d706747..ead60f0 100644 --- a/t/005_strict.t +++ b/t/005_strict.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 27; +use Test::More tests => 40; use Test::Exception; BEGIN { @@ -80,7 +80,7 @@ BEGIN { } -foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser::Descriptive)) { +foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser::Descriptive MooseX::Getopt::Parser::Default)) { SKIP: { if ($parser_name eq 'MooseX::Getopt::Parser::Descriptive') { eval { require Getopt::Long::Descriptive }; @@ -91,7 +91,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = (); my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); @@ -112,7 +112,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: throws_ok { my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); @@ -126,7 +126,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: throws_ok { my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); diff --git a/t/006_metaclass_traits.t b/t/006_metaclass_traits.t index aebe315..7e5eba5 100644 --- a/t/006_metaclass_traits.t +++ b/t/006_metaclass_traits.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 173; +use Test::More tests => 251; use Test::Moose; BEGIN { @@ -89,7 +89,7 @@ foreach my $attr_name (qw(data cow horse _private_stuff_cmdline)) { can_ok($attr, 'cmd_aliases'); } -foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser::Descriptive)) { +foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser::Descriptive MooseX::Getopt::Parser::Default)) { SKIP: { if ($parser_name eq 'MooseX::Getopt::Parser::Descriptive') { eval { require Getopt::Long::Descriptive }; @@ -100,7 +100,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = (); my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); @@ -119,7 +119,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = ('--verbose', '--length', 50); my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); @@ -138,7 +138,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = ('--verbose', '-f', 'foo.txt'); my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); @@ -157,7 +157,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = ('--verbose', '--libs', 'libs/', '--libs', 'includes/lib'); my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); @@ -178,7 +178,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = ('--details', 'os=mac', '--details', 'name=foo'); my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); @@ -200,7 +200,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = ('--noverbose'); my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); @@ -220,7 +220,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = ('--cow', '42'); my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); @@ -233,7 +233,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = ('--moocow', '88'); my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); @@ -246,7 +246,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = ('-c', '99'); my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); @@ -261,7 +261,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = ('--horsey', '123'); my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); @@ -274,7 +274,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = ('-x', '321'); my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); @@ -289,7 +289,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = ('-p', '666'); my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); @@ -305,7 +305,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = @args; my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); diff --git a/t/007_nogetopt_trait.t b/t/007_nogetopt_trait.t index a8e89c3..872a9cb 100644 --- a/t/007_nogetopt_trait.t +++ b/t/007_nogetopt_trait.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 23; +use Test::More tests => 34; use Test::Exception; BEGIN { @@ -81,7 +81,7 @@ BEGIN { } -foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser::Descriptive)) { +foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser::Descriptive MooseX::Getopt::Parser::Default)) { SKIP: { if ($parser_name eq 'MooseX::Getopt::Parser::Descriptive') { eval { require Getopt::Long::Descriptive }; @@ -92,7 +92,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: local @ARGV = (); my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); @@ -113,7 +113,7 @@ foreach my $parser_name (qw(MooseX::Getopt::Parser::Long MooseX::Getopt::Parser: throws_ok { my $parser = $parser_name->new; - isa_ok($parser, $parser_name); + ok(ref($parser) =~ /^MooseX::Getopt::Parser::/, '... parser object is created'); my $getopt = MooseX::Getopt::Session->new( parser => $parser ); isa_ok($getopt, 'MooseX::Getopt::Session'); diff --git a/t/100_gld_default_bug.t b/t/100_gld_default_bug.t index 4a2b42a..d37b524 100644 --- a/t/100_gld_default_bug.t +++ b/t/100_gld_default_bug.t @@ -9,16 +9,16 @@ use Test::Exception; BEGIN { eval 'use Getopt::Long::Descriptive;'; plan skip_all => "Getopt::Long::Descriptive required for this test" if $@; - plan tests => 5; + plan tests => 5; use_ok('MooseX::Getopt'); } { package Engine::Foo; use Moose; - + with 'MooseX::Getopt'; - + has 'nproc' => ( metaclass => 'Getopt', is => 'ro', @@ -43,6 +43,3 @@ BEGIN { is($foo->nproc, 1, '... got the right value (1), without GLD needing to handle defaults'); } - - -