| 1 | package MooseX::Getopt::GLD; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: A Moose role for processing command line options with Getopt::Long::Descriptive | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 12 | our $VERSION = '0.78'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 26 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 26 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 26 | ▶ | use MooseX::Role::Parameterized 1.01; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 26 | ▶ | use Getopt::Long::Descriptive 0.088; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 12 | with 'MooseX::Getopt::Basic'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 26 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | parameter getopt_conf => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | isa => 'ArrayRef[Str]', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 26 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 12 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 29 | ▶ | role { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 29 | my $p = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 29 | my $getopt_conf = $p->getopt_conf; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 29 | has usage => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | is => 'rw', isa => 'Getopt::Long::Descriptive::Usage', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | traits => ['NoGetopt'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # captures the options: --help --usage --? -? -h | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 29 | has help_flag => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | traits => ['Getopt'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | cmd_flag => 'help', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | cmd_aliases => [ qw(usage ? h) ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | documentation => 'Prints this usage information.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 95 | ▶ | around _getopt_spec => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 95 | shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 95 | shift->_gld_spec(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 29 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 95 | ▶ | around _getopt_get_options => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 95 | shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 95 | my ($class, $params, $opt_spec) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # Check if a special args hash were already passed, or create a new one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 95 | ▶ | my $args = ref($opt_spec->[-1]) eq 'HASH' ? pop @$opt_spec : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 95 | unshift @{$args->{getopt_conf}}, @$getopt_conf; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 95 | push @$opt_spec, $args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 95 | return Getopt::Long::Descriptive::describe_options($class->_usage_format(%$params), @$opt_spec); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 29 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 44 | ▶ | method _gld_spec => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
Subroutine
_gld_spec: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 44 | my ( $class, %params ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 44 | my ( @options, %name_to_init_arg ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 44 | my $constructor_params = $params{params}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 44 | foreach my $opt ( @{ $params{options} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | push @options, [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | $opt->{opt_string}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | $opt->{doc} || ' ', # FIXME new GLD shouldn't need this hack | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 268 | ▶ | ( ( $opt->{required} && !exists($constructor_params->{$opt->{init_arg}}) ) ? (required => $opt->{required}) : () ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition90%9/10
$opt->{'doc'} || ' '
$opt->{"required"} and not exists $$constructor_params{$opt->{"init_arg"}}
$opt->{'doc'} || ' '
$opt->{"required"} and not exists $$constructor_params{$opt->{"init_arg"}}
MC/DC100%1/1
$opt->{'doc'} || ' '
$opt->{'doc'}
MC/DC0%0/2
$opt->{"required"} and not exists $$constructor_params{$opt->{"init_arg"}}
$opt->{"required"}
not exists $$constructor_params{$opt->{"init_arg"}}
MC/DC100%1/1
$opt->{'doc'} || ' '
$opt->{'doc'}
MC/DC100%2/2
$opt->{"required"} and not exists $$constructor_params{$opt->{"init_arg"}}
$opt->{"required"}
not exists $$constructor_params{$opt->{"init_arg"}}
Truth table100%2/2
A
A= $opt->{'doc'}
Truth table66%2/3
A and not(B)
A= $opt->{"required"}B= not exists $$constructor_params{$opt->{"init_arg"}}
Truth table100%2/2
A
A= $opt->{'doc'}
Truth table100%3/3
A and not(B)
A= $opt->{"required"}B= not exists $$constructor_params{$opt->{"init_arg"}}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # NOTE: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | # remove this 'feature' because it didn't work | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | # all the time, and so is better to not bother | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # since Moose will handle the defaults just | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # fine anyway. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # - SL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | #( exists $opt->{default} ? (default => $opt->{default}) : () ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 268 | my $identifier = lc($opt->{name}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 268 | $identifier =~ s/\W/_/g; # Getopt::Long does this to all option names | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 268 | $name_to_init_arg{$identifier} = $opt->{init_arg}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 44 | return ( \@options, \%name_to_init_arg ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 29 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 12 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||