Yath.pm

filter: Statementstmt 90.4% 66 / 73 Branchbran 41.6% 10 / 24 Conditioncond 37.5% 6 / 16 MC/DCmcdc 10.0% 1 / 10 Subroutinesub 86.6% 13 / 15 Podpod n/a totaltotal 69.5% 96 / 138 CC 20 SCAR 23.9
CC
20
Cov
73%
__ANON__
42.0
import
7.3
__ANON__
7.3
CRAP 10.9
« Yath/Util.pm ↑ Summary Yath/Term.pm »
1 package Getopt::Yath;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 our $VERSION = '2.000008';
6  
7 1 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Getopt::Yath::Util qw/mod2file/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use Getopt::Yath::Instance;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Getopt::Yath::Option;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 sub import {
15 1 ▶ my $class = shift;
Subroutine import: called CC=6 SCAR=19.9
16 1 my %params = @_;
17  
18 1 my $caller = caller();
19  
20 1 ▶ my $inst_class = $params{inst_class} // 'Getopt::Yath::Instance';
Condition50%1/2
$params{"inst_class"} // "Getopt::Yath::Instance"
l!l
01
MC/DC0%0/1
$params{"inst_class"} // "Getopt::Yath::Instance"
$params{"inst_class"}
Truth table50%1/2
A
A= $params{"inst_class"}
Aresult
11
00
21  
22 1 my $instance = $inst_class->new(class => $class);
23 1 ▶ $instance->include($class->options) if $params{inherit} && $class->can('options');
Branch: 1 branch
BranchTrueFalseTotal
if $params{"inherit"} and $class->can("options") 0 1 1
Condition33%1/3
$params{"inherit"} and $class->can("options")
!ll&&!rl&&r
100
MC/DC0%0/2
$params{"inherit"} and $class->can("options")
$params{"inherit"} $class->can("options")
Truth table33%1/3
A and B
A= $params{"inherit"}B= $class->can("options")
ABresult
0X0
100
111
24  
25 1 my %export;
26 my @common;
27 1 ▶ $export{options} = sub { $instance };
Subroutine __ANON__: called CC=1 SCAR=0.0
28  
29 $export{option} = sub {
30 16 ▶ my $title = shift;
Subroutine __ANON__: called CC=2 SCAR=7.0
31 16 ▶ my $option = Getopt::Yath::Option->create(trace => [caller()], title => $title, @common ? (%{$common[-1]}) : (), @_);
Branch: 1 branch
BranchTrueFalseTotal
@common ? : 16 0 16
32 15 $instance->_option($option);
33 1 };
34  
35 $export{include_options} = sub {
36 0 ▶ while (my $module = shift @_) {
Subroutine __ANON__: not called CC=6 SCAR=37.4
Branch: 1 branch
BranchTrueFalseTotal
if (my $module = shift @_) 0 0 0
37 0 my $file = mod2file($module);
38 0 ▶ require $file unless $INC{$file};
Branch: 1 branch
BranchTrueFalseTotal
unless $INC{$file} 0 0 0
39  
40 0 ▶ croak "Module '$module' does not have an 'options' method"
Branch: 1 branch
BranchTrueFalseTotal
unless $module->can("options") 0 0 0
41 unless $module->can('options');
42  
43 0 ▶ my $list = @_ && ref($_[0]) eq 'ARRAY' ? shift(@_) : undef;
Branch: 1 branch
BranchTrueFalseTotal
@_ && ref $_[0] eq 'ARRAY' ? : 0 0 0
Condition0%0/3
@_ and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
@_ and ref $_[0] eq "ARRAY"
@_ ref $_[0] eq "ARRAY"
Truth table0%0/3
A and B
A= @_B= ref $_[0] eq "ARRAY"
ABresult
0X0
100
111
44  
45 0 $instance->include($module->options, $list);
46 }
47 1 };
48  
49 $export{option_post_process} = sub {
50 4 ▶ my $cb = pop;
Subroutine __ANON__: called CC=6 SCAR=19.9
51 4 ▶ my $weight = shift // 0;
Condition100%2/2
shift() // 0
l!l
31
MC/DC100%1/1
shift() // 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
52 4 my ($applicable) = @_;
53  
54 4 ▶ $applicable //= $common[-1]->{applicable} if @common;
Branch: 1 branch
BranchTrueFalseTotal
if @common 4 0 4
Condition33%1/3
$applicable //= $common[-1]{"applicable"}
l!l&&r!l&&!r
004
MC/DC0%0/2
$applicable //= $common[-1]{"applicable"}
$applicable $common[-1]{"applicable"}
Truth table33%1/3
A //= B
A= $applicableB= $common[-1]{"applicable"}
ABresult
1X1
011
000
55  
56 4 ▶ croak "You must provide a callback coderef" unless $cb && ref($cb) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless $cb and ref $cb eq "CODE" 0 4 4
Condition33%1/3
$cb and ref $cb eq "CODE"
!ll&&!rl&&r
004
MC/DC0%0/2
$cb and ref $cb eq "CODE"
$cb ref $cb eq "CODE"
Truth table33%1/3
A and B
A= $cbB= ref $cb eq "CODE"
ABresult
0X0
100
111
57  
58 4 $instance->_post([caller()], $weight, $applicable, $cb);
59 1 };
60  
61 $export{option_group} = sub {
62 2 ▶ my ($set, $sub) = @_;
Subroutine __ANON__: called CC=4 SCAR=13.9
63  
64 2 ▶ my $common = {@common ? (%{$common[-1]}) : (), %$set};
Branch: 1 branch
BranchTrueFalseTotal
@common ? : 1 1 2
65  
66 2 ▶ $common->{module} = caller unless $common->{no_module};
Branch: 1 branch
BranchTrueFalseTotal
unless $common->{"no_module"} 1 1 2
67  
68 2 push @common => $common;
69 2 my $ok = eval { $sub->(); 1 };
70 2 my $err = $@;
71 2 pop @common;
72  
73 2 ▶ die $err unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 2 2
74 1 };
75  
76 1 ▶ $export{parse_options} = sub { $instance->process_args(@_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
77  
78 1 ▶ $export{category_sort_map} = sub { $instance->set_category_sort_map(@_) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
79  
80 1 for my $name (keys %export) {
81 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
82 croak "$caller already has an '$name' method"
83 7 ▶ if defined(&{"${caller}\::${name}"});
Branch: 1 branch
BranchTrueFalseTotal
if defined &{"${caller}::$name";} 0 7 7
84  
85 7 *{"${caller}\::${name}"} = $export{$name};
86 }
87  
88 1 return 1;
89 }
90  
91 1 1;
92  
93 __END__
« Yath/Util.pm ↑ Summary Yath/Term.pm »