2 package MooseX::Getopt::Parser::Long;
6 with 'MooseX::Getopt::Parser';
9 use MooseX::Getopt::OptionTypeMap;
12 # Special configuration for parser
15 isa => 'ArrayRef[Str]',
17 default => sub { [] },
23 my ($getopt, @attrs) = @_;
25 Moose->throw_error('First argument is not a MooseX::Getopt::Session')
26 unless $getopt->isa('MooseX::Getopt::Session');
28 my $options = $getopt->options;
31 foreach my $attr (@attrs) {
32 my $name = $attr->name;
34 my ($flag, @aliases) = $getopt->_get_cmd_flags_for_attr($attr);
35 my $type = $getopt->_get_cmd_type_for_attr($attr);
37 my $opt_string = join '|', $flag, @aliases;
38 $opt_string .= MooseX::Getopt::OptionTypeMap->get_option_type($type) if $type;
40 $options->{$name} = undef;
41 push @opts, $opt_string => \$options->{$name};
47 my $parser = new Getopt::Long::Parser;
48 $parser->configure( $self->config );
50 local @ARGV = @{ $getopt->ARGV };
52 local $SIG{__WARN__} = sub {
53 return warn @_ if $_[0]=~/^\###/; # Smart::Comments
57 $parser->getoptions( @opts );
59 my $extra_argv = \@ARGV;
60 $getopt->extra_argv( $extra_argv );
63 # Filter not defined values in options hashref
64 $options = { map { $_ => $options->{$_} } grep { defined $options->{$_} } keys %$options };
66 $getopt->options( $options );
68 die $warnings if $warnings;
82 MooseX::Getopt::Parser::Long - A Getopt::Long parser for MooseX::Getopt
86 use MooseX::Getopt::Parser::Long;
88 my $parser = MooseX::Getopt::Parser::Long->new( config => ['pass_through'] );
89 my $getopt = MooseX::Getopt::Session->new( parser => $parser );
90 my $app = My::App->new( getopt => $getopt );
94 This class does L<MooseX::Getopt::Parser> for L<MooseX::Getopt>. This
95 class is used by default if L<Getopt::Long::Descriptive> module is
102 =item B<build_options ($getopt, @attrs)>
104 This method parses the CLI options with L<Getopt::Long> and returns a hashref to options list.
106 The first argument have to be L<MooseX::Getopt::Session> object and
107 second argument is a list of attributes which contains options.
111 This accessor contains the arrayref to list with special configuration
112 keywords for L<Getopt::Long>.
118 All complex software has bugs lurking in it, and this module is no
119 exception. If you find a bug please either email me, or add the bug
126 =item L<MooseX::Getopt::Parser>
128 =item L<MooseX::Getopt::Parser::Default>
130 =item L<MooseX::Getopt::Parser::Descriptive>
132 =item L<Getopt::Long>
138 Piotr Roszatycki, E<lt>dexter@cpan.orgE<gt>
140 =head1 COPYRIGHT AND LICENSE
142 Copyright 2007-2008 by Infinity Interactive, Inc.
144 L<http://www.iinteractive.com>
146 This library is free software; you can redistribute it and/or modify
147 it under the same terms as Perl itself.