2 package MooseX::Getopt::Parser::Long;
4 our $VERSION = '0.150001';
8 with 'MooseX::Getopt::Parser';
10 use MooseX::Getopt::OptionTypeMap;
15 # Special configuration for parser
18 isa => 'ArrayRef[Str]',
20 default => sub { ['default'] },
26 my ( $getopt, @attrs ) = @_;
28 Moose->throw_error("First argument is not a MooseX::Getopt::Session")
29 unless $getopt->isa('MooseX::Getopt::Session');
31 my $options = $getopt->options;
32 my $new_options = { %$options };
36 foreach my $attr (@attrs) {
37 my $name = $attr->name;
39 my ( $flag, @aliases ) = $getopt->_get_cmd_flags_for_attr($attr);
40 my $type = $getopt->_get_cmd_type_for_attr($attr);
42 my $opt_string = join '|', $flag, @aliases;
43 $opt_string .= MooseX::Getopt::OptionTypeMap->get_option_type($type)
46 $new_options->{$name} = undef;
47 push @opts, $opt_string => \$new_options->{$name};
53 my $parser = new Getopt::Long::Parser;
54 $parser->configure( $self->config );
56 local @ARGV = @{ $getopt->ARGV };
58 local $SIG{__WARN__} = sub {
62 $parser->getoptions( @opts );
64 my $extra_argv = \@ARGV;
65 $getopt->extra_argv( $extra_argv );
68 # Filter not defined values in new_options hashref
70 map { $_ => $new_options->{$_} }
71 grep { defined $new_options->{$_} } keys %$new_options
74 $getopt->status( ! $warnings );
75 $getopt->options( $new_options );
77 die $warnings if $warnings;
92 MooseX::Getopt::Parser::Long - A Getopt::Long parser for MooseX::Getopt
96 use MooseX::Getopt::Parser::Long;
98 my $parser = MooseX::Getopt::Parser::Long->new( config => ['pass_through'] );
99 my $getopt = MooseX::Getopt::Session->new( parser => $parser );
100 my $app = My::App->new( getopt => $getopt );
104 This class does L<MooseX::Getopt::Parser> for L<MooseX::Getopt>. This
105 class is used by default if L<Getopt::Long::Descriptive> module is
112 =item B<build_options ($getopt, @attrs)>
114 This method parses the CLI options with L<Getopt::Long> and returns a hashref to options list.
116 The first argument have to be L<MooseX::Getopt::Session> object and
117 second argument is a list of attributes which contains options.
121 This accessor contains the arrayref to list with special configuration
122 keywords for L<Getopt::Long>.
128 All complex software has bugs lurking in it, and this module is no
129 exception. If you find a bug please either email me, or add the bug
136 =item L<MooseX::Getopt::Parser>
138 =item L<MooseX::Getopt::Parser::Default>
140 =item L<MooseX::Getopt::Parser::Descriptive>
142 =item L<Getopt::Long>
148 Piotr Roszatycki, E<lt>dexter@cpan.orgE<gt>
150 =head1 COPYRIGHT AND LICENSE
152 Copyright 2007-2008 by Infinity Interactive, Inc.
154 L<http://www.iinteractive.com>
156 This library is free software; you can redistribute it and/or modify
157 it under the same terms as Perl itself.