2 package MooseX::Getopt::Parser::Long;
6 with 'MooseX::Getopt::Parser';
8 use MooseX::Getopt::OptionTypeMap;
13 # Special configuration for parser
16 isa => 'ArrayRef[Str]',
18 default => sub { [ 'default' ] },
24 my ($getopt, @attrs) = @_;
26 Moose->throw_error('First argument is not a MooseX::Getopt::Session')
27 unless $getopt->isa('MooseX::Getopt::Session');
29 my $options = $getopt->options;
30 my $new_options = { %$options };
34 foreach my $attr (@attrs) {
35 my $name = $attr->name;
37 my ($flag, @aliases) = $getopt->_get_cmd_flags_for_attr($attr);
38 my $type = $getopt->_get_cmd_type_for_attr($attr);
40 my $opt_string = join '|', $flag, @aliases;
41 $opt_string .= MooseX::Getopt::OptionTypeMap->get_option_type($type) if $type;
43 $new_options->{$name} = undef;
44 push @opts, $opt_string => \$new_options->{$name};
50 my $parser = new Getopt::Long::Parser;
51 $parser->configure( $self->config );
53 local @ARGV = @{ $getopt->ARGV };
55 local $SIG{__WARN__} = sub {
59 $parser->getoptions( @opts );
61 my $extra_argv = \@ARGV;
62 $getopt->extra_argv( $extra_argv );
65 # Filter not defined values in new_options hashref
66 $new_options = { map { $_ => $new_options->{$_} } grep { defined $new_options->{$_} } keys %$new_options };
68 $getopt->status( ! $warnings );
69 $getopt->options( $new_options );
71 die $warnings if $warnings;
85 MooseX::Getopt::Parser::Long - A Getopt::Long parser for MooseX::Getopt
89 use MooseX::Getopt::Parser::Long;
91 my $parser = MooseX::Getopt::Parser::Long->new( config => ['pass_through'] );
92 my $getopt = MooseX::Getopt::Session->new( parser => $parser );
93 my $app = My::App->new( getopt => $getopt );
97 This class does L<MooseX::Getopt::Parser> for L<MooseX::Getopt>. This
98 class is used by default if L<Getopt::Long::Descriptive> module is
105 =item B<build_options ($getopt, @attrs)>
107 This method parses the CLI options with L<Getopt::Long> and returns a hashref to options list.
109 The first argument have to be L<MooseX::Getopt::Session> object and
110 second argument is a list of attributes which contains options.
114 This accessor contains the arrayref to list with special configuration
115 keywords for L<Getopt::Long>.
121 All complex software has bugs lurking in it, and this module is no
122 exception. If you find a bug please either email me, or add the bug
129 =item L<MooseX::Getopt::Parser>
131 =item L<MooseX::Getopt::Parser::Default>
133 =item L<MooseX::Getopt::Parser::Descriptive>
135 =item L<Getopt::Long>
141 Piotr Roszatycki, E<lt>dexter@cpan.orgE<gt>
143 =head1 COPYRIGHT AND LICENSE
145 Copyright 2007-2008 by Infinity Interactive, Inc.
147 L<http://www.iinteractive.com>
149 This library is free software; you can redistribute it and/or modify
150 it under the same terms as Perl itself.