| 1 | package CLI::Driver::Class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 attr => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | ############################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | ###### PUBLIC METHODS ###### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | ############################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # self->name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 196 | ▶ | if ( !$href->{name} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | $self->warn("failed to find class name"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | return 0; # failed | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 196 | $self->name( $href->{name} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # self->attr | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 196 | my $attr = $self->_parse_attrs( href => $href ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 196 | ▶ | if ( !$attr ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | return 0; # failed | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 196 | $self->attr($attr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 196 | return 1; # success | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | method find_req_attrs (Bool :$hard = 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 15 | ▶ | Bool :$soft = 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
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
find_req_attrs: called CC=18 SCAR=30.2
Branch: 9 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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 24 | my @req; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 24 | my @opts = @{ $self->attr }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 24 | foreach my $opt (@opts) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 25 | ▶ | if ( $opt->is_required ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 15 | ▶ | if ( $hard and $opt->is_hard ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$hard and $opt->is_hard
MC/DC0%0/2
$hard and $opt->is_hard
$hard
$opt->is_hard
Truth table33%1/3
A and B
A= $hardB= $opt->is_hard
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | push @req, $opt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | ▶ | elsif ( $soft and $opt->is_soft ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$soft and $opt->is_soft
MC/DC50%1/2
$soft and $opt->is_soft
$soft
$opt->is_soft
Truth table66%2/3
A and B
A= $softB= $opt->is_soft
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | push @req, $opt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # drop it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 24 | return @req; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 15 | ▶ | method get_signature { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
get_signature: called CC=7 SCAR=19.5
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 26 | my %return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 26 | my @opts = @{ $self->attr }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 26 | foreach my $opt (@opts) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 28 | my %sig = $opt->get_signature; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 28 | my @keys = keys %sig; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 28 | ▶ | if ( @keys == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # happy path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 19 | my $key = shift @keys; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 19 | $return{$key} = $sig{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | elsif ( @keys > 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | confess "should not get here"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | ▶ | elsif ( $opt->is_required and $opt->is_hard ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$opt->is_required and $opt->is_hard
MC/DC100%2/2
$opt->is_required and $opt->is_hard
$opt->is_required
$opt->is_hard
Truth table100%3/3
A and B
A= $opt->is_requiredB= $opt->is_hard
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 2 | my $msg = sprintf( "missing args: -%s <%s>", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | $opt->cli_arg, $opt->method_arg ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 2 | confess $msg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 24 | return %return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | ######################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 15 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||