blib/lib/XXX.pm

filter: Statementstmt 65.1% 58 / 89 Branchbran 42.0% 21 / 50 Conditioncond 11.7% 2 / 17 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 78.5% 11 / 14 Podpod 100% 4 / 4 totaltotal 52.4% 96 / 183 CC 31 SCAR 30.9
CC
31
Cov
52%
_xxx_dump
39.9
WWW
30.0
YYY
30.0
CRAP 21.9
↑ Summary
1 4 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package XXX;
3 4 our $VERSION = '0.37';
4 4 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 our @EXPORT = qw( WWW XXX YYY ZZZ );
7  
8 4 our $DumpModule = 'YAML::PP';
9  
10 4 ▶if ($ENV{PERL_XXX_DUMPER}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"PERL_XXX_DUMPER"}) 0 4 4
11 0 _set_dump_module($ENV{PERL_XXX_DUMPER});
12 }
13  
14 sub import {
15 3 ▶ my ($package, @args) = @_;
Subroutine import: called CC=5 SCAR=19.7
16 3 ▶ for (my $i = 0; $i < @args; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @args) 1 2 3
17 1 my $arg = $args[$i];
18 1 ▶ if ($arg eq '-with') {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg eq '-with') { } 1 0 1
19 1 ▶ die "-with requires another argument"
Branch: 1 branch
BranchTrueFalseTotal
unless $i++ < @args 0 1 1
20 unless $i++ < @args;
21 1 _set_dump_module($args[ $i ]);
22 }
23 else {
24 0 next;
25 }
26 1 last;
27 }
28 3 ▶ if (grep /^-?global$/, @args) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep /^-?global$/, @args) 0 3 3
29 0 *main::WWW = \&WWW;
30 0 *main::XXX = \&XXX;
31 0 *main::YYY = \&YYY;
32 0 *main::ZZZ = \&ZZZ;
33 0 $main::WWW = \&WWW;
34 0 $main::XXX = \&XXX;
35 0 $main::YYY = \&YYY;
36 0 $main::ZZZ = \&ZZZ;
37 }
38 3 @_ = ($package);
39 3 goto &Exporter::import;
40 }
41  
42 sub _set_dump_module {
43 1 ▶ my ($module) = @_;
Subroutine _set_dump_module: called CC=2 SCAR=7.1
44 1 $DumpModule = $module;
45 1 ▶ die "Don't know how to use XXX -with '$DumpModule'"
Branch: 1 branch
BranchTrueFalseTotal
unless $XXX::DumpModule =~ /^( (?:YAML|JSON)(?:::.*)?| Data::Dumper| Data::Dump(?:::Color)? )$/x 0 1 1
46 unless $DumpModule =~ /^(
47 (?:YAML|JSON)(?:::.*)?|
48 Data::Dumper|
49 Data::Dump(?:::Color)?
50 )$/x;
51 }
52  
53 sub _xxx_dump {
54 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
55 4 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
56 3 ▶ $DumpModule ||= 'YAML::PP';
Subroutine _xxx_dump: called CC=15 SCAR=36.9
Condition50%1/2
$XXX::DumpModule ||= "YAML::PP"
l!l
30
MC/DC0%0/1
$XXX::DumpModule ||= "YAML::PP"
$XXX::DumpModule
Truth table50%1/2
A
A= $XXX::DumpModule
Aresult
11
00
57 3 ▶ my $dump_type =
Branch: 5 branches
BranchTrueFalseTotal
substr($XXX::DumpModule, 0, 4) eq 'YAML' ? : 2 1 3
substr($XXX::DumpModule, 0, 4) eq 'JSON' ? : 0 1 1
$XXX::DumpModule eq 'Data::Dumper' ? : 1 0 1
$XXX::DumpModule eq 'Data::Dump' ? : 0 0 0
$XXX::DumpModule eq 'Data::Dump::Color' ? : 0 0 0
58 (substr($DumpModule, 0, 4) eq 'YAML') ? 'yaml' :
59 (substr($DumpModule, 0, 4) eq 'JSON') ? 'json' :
60 ($DumpModule eq 'Data::Dumper') ? 'dumper' :
61 ($DumpModule eq 'Data::Dump') ? 'dump' :
62 ($DumpModule eq 'Data::Dump::Color') ? 'dumpcolor' :
63 die 'Invalid dump module in $DumpModule';
64 3 ▶ if (not defined ${"$DumpModule\::VERSION"}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined ${"$XXX::DumpModule::VERSION";}) 2 1 3
65 2 ▶ eval "require $DumpModule; 1" or die $@;
Branch: 1 branch
BranchTrueFalseTotal
eval "require $XXX::DumpModule; 1" or die $@ 0 2 2
66 }
67 3 ▶ if ($DumpModule eq 'YAML::PP') {
Branch: 1 branch
BranchTrueFalseTotal
if ($XXX::DumpModule eq "YAML::PP") 2 1 3
68 2 return YAML::PP->new(schema => ['Core', 'Perl'])->dump_string(@_) . "...\n";
69 }
70 1 ▶ if ($dump_type eq 'yaml') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dump_type eq "yaml") 0 1 1
71 0 return &{"$DumpModule\::Dump"}(@_) . "...\n";
72 }
73 1 ▶ if ($dump_type eq 'json') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dump_type eq "json") 0 1 1
74 0 return &{"$DumpModule\::encode_json"}(@_);
75 }
76 1 ▶ if ($dump_type eq 'dumper') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dump_type eq "dumper") 1 0 1
77 1 local $Data::Dumper::Sortkeys = 1;
78 1 local $Data::Dumper::Indent = 2;
79 1 return Data::Dumper::Dumper(@_);
80 }
81 0 ▶ if ($dump_type eq 'dump') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dump_type eq "dump") 0 0 0
82 0 return Data::Dump::dump(@_) . "\n";
83 }
84 0 ▶ if ($dump_type eq 'dumpcolor') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dump_type eq "dumpcolor") 0 0 0
85 0 return Data::Dump::Color::dump(@_) . "\n";
86 }
87 0 die "XXX had an internal error";
88 }
89  
90 sub _at_line_number {
91 3 ▶ my ($file_path, $line_number);
Subroutine _at_line_number: called CC=4 SCAR=14.3
92 3 my $caller = 0;
93 3 ▶ while (++$caller) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$caller) 3 0 3
94 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
95 3 my $skipper = (caller($caller))[0] . "::XXX_skip";
96 3 ▶ next if defined &$skipper and &$skipper();
Branch: 1 branch
BranchTrueFalseTotal
if defined &$skipper and &$skipper() 0 3 3
Condition33%1/3
defined &$skipper and &$skipper()
!ll&&!rl&&r
300
MC/DC0%0/2
defined &$skipper and &$skipper()
defined &$skipper &$skipper()
Truth table33%1/3
A and B
A= defined &$skipperB= &$skipper()
ABresult
0X0
100
111
97 3 ($file_path, $line_number) = (caller($caller))[1,2];
98 3 last;
99 }
100 3 " at $file_path line $line_number\n";
101 }
102  
103 sub WWW {
104 0 ▶ my $dump = _xxx_dump(@_) . _at_line_number();
Subroutine WWW: not called CC=5 SCAR=34.0
Pod documented
105 0 ▶ if (defined &main::diag and
Branch: 1 branch
BranchTrueFalseTotal
if (defined &main::diag and defined &Test::More::diag and \&main::diag eq \&Test::More::diag) { } 0 0 0
Condition0%0/6
defined &main::diag and defined &Test::More::diag and \&main::diag eq \&Test::More::diag
!ll&&!rl&&r
000
defined &main::diag and defined &Test::More::diag
!ll&&!rl&&r
000
MC/DC0%0/3
defined &main::diag and defined &Test::More::diag and \&main::diag eq \&Test::More::diag
defined &main::diag defined &Test::More::diag \&main::diag eq \&Test::More::diag
Truth table0%0/4
A and B and C
A= defined &main::diagB= defined &Test::More::diagC= \&main::diag eq \&Test::More::diag
ABCresult
0XX0
10X0
1100
1111
106 defined &Test::More::diag and
107 \&main::diag eq \&Test::More::diag
108 ) {
109 0 main::diag($dump);
110 }
111 else {
112 0 warn($dump);
113 }
114 0 ▶ return wantarray ? @_ : $_[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
115 }
116  
117 sub XXX {
118 3 ▶ die _xxx_dump(@_) . _at_line_number();
Subroutine XXX: called CC=1 SCAR=0.0
Pod documented
119 }
120  
121 sub YYY {
122 0 ▶ my $dump = _xxx_dump(@_) . _at_line_number();
Subroutine YYY: not called CC=5 SCAR=34.0
Pod documented
123 0 ▶ if (defined &main::note and
Branch: 1 branch
BranchTrueFalseTotal
if (defined &main::note and defined &Test::More::note and \&main::note eq \&Test::More::note) { } 0 0 0
Condition0%0/6
defined &main::note and defined &Test::More::note and \&main::note eq \&Test::More::note
!ll&&!rl&&r
000
defined &main::note and defined &Test::More::note
!ll&&!rl&&r
000
MC/DC0%0/3
defined &main::note and defined &Test::More::note and \&main::note eq \&Test::More::note
defined &main::note defined &Test::More::note \&main::note eq \&Test::More::note
Truth table0%0/4
A and B and C
A= defined &main::noteB= defined &Test::More::noteC= \&main::note eq \&Test::More::note
ABCresult
0XX0
10X0
1100
1111
124 defined &Test::More::note and
125 \&main::note eq \&Test::More::note
126 ) {
127 0 main::note($dump);
128 }
129 else {
130 0 print($dump);
131 }
132 0 ▶ return wantarray ? @_ : $_[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
133 }
134  
135 sub ZZZ {
136 0 ▶ require Carp;
Subroutine ZZZ: not called CC=1 SCAR=6.9
Pod documented
137 0 Carp::confess(_xxx_dump(@_));
138 }
139  
140 4 1;
↑ Summary