* Handling with Getopt parser implemented as strategy pattern.
[gitmo/MooseX-Getopt.git] / lib / MooseX / Getopt / Parser / Long.pm
CommitLineData
550da402 1
2package MooseX::Getopt::Parser::Long;
3
4use Moose;
5
6with 'MooseX::Getopt::Parser';
7
8sub 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
18sub _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
351;