| 1 | package CLI::Driver::Method; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 15 | ▶ | use Modern::Perl; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 15 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 15 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 15 | ▶ | use Kavorka '-all'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 15 | ▶ | use Data::Printer alias => 'pdump'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 15 | ▶ | use CLI::Driver::Option; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 15 | with | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 'CLI::Driver::CommonRole', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 'CLI::Driver::ArgParserRole'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | ############################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | ###### PUBLIC ATTRIBUTES ###### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | ############################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 15 | has name => ( is => 'rw' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | has args => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | isa => 'ArrayRef[CLI::Driver::Option]', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 196 | ▶ | default => sub { [] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 15 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 15 | ▶ | method parse (HashRef :$href!) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
parse: called CC=13 SCAR=27.1
Branch: 8 branches
Condition33%1/3
$#_ == 0 and ref $_[0] eq "HASH"
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0
ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # self->name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 196 | ▶ | if ( !$href->{name} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | $self->warn("failed to find method name"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | return 0; # failed | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 196 | $self->name( $href->{name} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # self->args | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 196 | my $args = $self->_parse_args( href => $href ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 196 | ▶ | if ( !$args ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | return 0; # failed | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 196 | $self->args($args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 196 | return 1; # success | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 15 | ▶ | method get_signature { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
get_signature: called CC=7 SCAR=19.5
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 23 | my %return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 23 | my @opts = @{ $self->args }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 23 | foreach my $opt (@opts) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 35 | my %sig = $opt->get_signature; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 35 | my @keys = keys %sig; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 35 | ▶ | if ( @keys == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 24 | my $key = shift @keys; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 24 | $return{$key} = $sig{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | elsif ( @keys > 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | confess "should not get here"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | ▶ | elsif ( $opt->required and $opt->is_hard ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$opt->required and $opt->is_hard
MC/DC100%2/2
$opt->required and $opt->is_hard
$opt->required
$opt->is_hard
Truth table100%3/3
A and B
A= $opt->requiredB= $opt->is_hard
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 3 | my $msg = sprintf( "missing args: -%s <%s>", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | $opt->cli_arg, $opt->method_arg ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 3 | confess $msg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 20 | return %return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 15 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||