| 1 | package CLI::Driver::Class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 17 | ▶ | use Modern::Perl; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 17 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 17 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 17 | ▶ | use Kavorka '-all'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 17 | ▶ | use Data::Printer alias => 'pdump'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 17 | ▶ | use CLI::Driver::Option; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 17 | with | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 'CLI::Driver::CommonRole', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 'CLI::Driver::ArgParserRole'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | ############################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | ###### PUBLIC ATTRIBUTES ###### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | ############################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 17 | has name => ( is => 'rw' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | has attr => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | isa => 'ArrayRef[CLI::Driver::Option]', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 240 | ▶ | default => sub { [] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 17 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 17 | has 'use_argv_map' => ( is => 'rw', isa => 'Bool' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | ############################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | ###### PUBLIC METHODS ###### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | ############################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 17 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # self->name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 240 | ▶ | if ( !$href->{name} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | $self->warn("failed to find class name"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | return 0; # failed | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 240 | $self->name( $href->{name} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # self->attr | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 240 | my $attr = $self->_parse_attrs( href => $href ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 240 | ▶ | if ( !$attr ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | return 0; # failed | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 240 | $self->attr($attr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 240 | return 1; # success | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | method find_req_attrs (Bool :$hard = 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 17 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 28 | my @req; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 28 | my @opts = @{ $self->attr }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 28 | foreach my $opt (@opts) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 27 | ▶ | if ( $opt->is_required ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 16 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | push @req, $opt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 2 | push @req, $opt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # drop it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 28 | return @req; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 17 | ▶ | method get_signature { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
get_signature: called CC=7 SCAR=19.5
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 30 | my %return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 30 | my @opts = @{ $self->attr }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 30 | foreach my $opt (@opts) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 29 | my %sig = $opt->get_signature; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 29 | my @keys = keys %sig; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 29 | ▶ | if ( @keys == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # happy path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 21 | my $key = shift @keys; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 21 | $return{$key} = $sig{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | elsif ( @keys > 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | confess "should not get here"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 2 | my $msg = sprintf( "missing args: -%s <%s>", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | $opt->cli_arg, $opt->method_arg ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 2 | confess $msg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 28 | return %return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | ######################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 17 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||