Commit | Line | Data |
550da402 |
1 | |
2 | package MooseX::Getopt::Parser::Long; |
3 | |
4 | use Moose; |
5 | |
6 | with 'MooseX::Getopt::Parser'; |
7 | |
8 | sub getoptions { |
9 | my ($class, $opt_spec) = @_; |
10 | |
11 | my %options; |
12 | |
13 | my $getopt = Getopt::Long::Parser->new; |
14 | $getopt->getoptions(\%options, @$opt_spec); |
15 | return ( \%options, undef ); |
16 | } |
17 | |
18 | sub _get_getopt_spec { |
19 | my ($class, %params) = @_; |
20 | |
21 | my ( @options, %name_to_init_arg, %options ); |
22 | |
23 | foreach my $opt ( @{ $params{options} } ) { |
24 | push @options, $opt->{opt_string}; |
25 | |
26 | my $identifier = $opt->{name}; |
27 | $identifier =~ s/\W/_/g; # Getopt::Long does this to all option names |
28 | |
29 | $name_to_init_arg{$identifier} = $opt->{init_arg}; |
30 | } |
31 | |
32 | return ( \@options, \%name_to_init_arg ); |
33 | } |
34 | |
35 | 1; |