lib/CLI/Driver/Method.pm

filter: Statementstmt 93.3% 84 / 90 Branchbran 60.7% 17 / 28 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 15 / 15 Podpod n/a totaltotal 85.3% 122 / 143 CC 19 SCAR 20.5
CC
19
Cov
85%
parse
15.0
get_signature
7.0
BEGIN
1.0
CRAP 7.8
« lib/CLI/Driver.pm ↑ Summary lib/CLI/Driver/Help.pm »
1 package CLI::Driver::Method;
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 args => (
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
BranchTrueFalseTotal
@_ ? : 240 0 240
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 240 240
if ($slice_length % 2 != 0) 0 240 240
if ($i <= $#_) 240 240 480
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 240 240
exists $_{'href'} ? : 240 0 240
if (exists $_{"href"}) 240 0 240
Ref::Util::XS::is_plain_hashref($href) or _failed_check(22, "HashRef", $href, "exception_class", "Error::TypeTiny::Assertion") 0 240 240
Condition33%1/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
24000
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"
ABresult
0X0
100
111
33  
34 # self->name
35 240 ▶ if ( !$href->{name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $href->{'name'}) { } 0 240 240
36 0 $self->warn("failed to find method name");
37 0 return 0; # failed
38 }
39 else {
40 240 $self->name( $href->{name} );
41 }
42  
43 # self->args
44 240 my $args = $self->_parse_args( href => $href );
45 240 ▶ if ( !$args ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $args) { } 0 240 240
46 0 return 0; # failed
47 }
48 else {
49 240 $self->args($args);
50 }
51  
52 240 return 1; # success
53 }
54  
55 17 ▶method get_signature {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine get_signature: called CC=7 SCAR=19.5
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 27 0 27
56  
57 27 my %return;
58 27 my @opts = @{ $self->args };
59  
60 27 foreach my $opt (@opts) {
61  
62 39 my %sig = $opt->get_signature;
63 39 my @keys = keys %sig;
64  
65 39 ▶ if ( @keys == 1 ) {
Branch: 3 branches
BranchTrueFalseTotal
if (@keys == 1) { } 28 11 39
elsif (@keys > 1) { } 0 11 11
elsif ($opt->required and $opt->is_hard) { } 3 14 17
66 28 my $key = shift @keys;
67 28 $return{$key} = $sig{$key};
68 }
69 elsif ( @keys > 1 ) {
70 0 confess "should not get here";
71 }
72 ▶ elsif ( $opt->required and $opt->is_hard ) {
Condition100%3/3
$opt->required and $opt->is_hard
!ll&&!rl&&r
623
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
ABresult
0X0
100
111
73 3 my $msg = sprintf( "missing args: -%s <%s>",
74 $opt->cli_arg, $opt->method_arg );
75 3 confess $msg;
76 }
77 }
78  
79 24 return %return;
80 }
81  
82 17 1;
« lib/CLI/Driver.pm ↑ Summary lib/CLI/Driver/Help.pm »