X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FGetopt%2FParser%2FDescriptive.pm;h=c60839cccac2f04459126cd49de1f7998aea92ea;hb=ac2073c861c686a00941f7b6d5c9c1b4013d7671;hp=3e71d346ed0227946d1917e4f49523ff9b8f2d30;hpb=05e8fe8973c9305d2a81ee513474cd5f78a0fef3;p=gitmo%2FMooseX-Getopt.git 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