blib/lib/XXX.pm

filter: Statementstmt 68.2% 58 / 85 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 53.6% 96 / 179 CC 31 SCAR 30.8
CC
31
Cov
53%
_xxx_dump
39.9
WWW
30.0
YYY
30.0
CRAP 21.8
↑ 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.36';
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=18.0
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 }
34 3 @_ = ($package);
35 3 goto &Exporter::import;
36 }
37  
38 sub _set_dump_module {
39 1 ▶ my ($module) = @_;
Subroutine _set_dump_module: called CC=2 SCAR=7.1
40 1 $DumpModule = $module;
41 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
42 unless $DumpModule =~ /^(
43 (?:YAML|JSON)(?:::.*)?|
44 Data::Dumper|
45 Data::Dump(?:::Color)?
46 )$/x;
47 }
48  
49 sub _xxx_dump {
50 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
51 4 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
52 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
53 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
54 (substr($DumpModule, 0, 4) eq 'YAML') ? 'yaml' :
55 (substr($DumpModule, 0, 4) eq 'JSON') ? 'json' :
56 ($DumpModule eq 'Data::Dumper') ? 'dumper' :
57 ($DumpModule eq 'Data::Dump') ? 'dump' :
58 ($DumpModule eq 'Data::Dump::Color') ? 'dumpcolor' :
59 die 'Invalid dump module in $DumpModule';
60 3 ▶ if (not defined ${"$DumpModule\::VERSION"}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined ${"$XXX::DumpModule::VERSION";}) 2 1 3
61 2 ▶ eval "require $DumpModule; 1" or die $@;
Branch: 1 branch
BranchTrueFalseTotal
eval "require $XXX::DumpModule; 1" or die $@ 0 2 2
62 }
63 3 ▶ if ($DumpModule eq 'YAML::PP') {
Branch: 1 branch
BranchTrueFalseTotal
if ($XXX::DumpModule eq "YAML::PP") 2 1 3
64 2 return YAML::PP->new(schema => ['Core', 'Perl'])->dump_string(@_) . "...\n";
65 }
66 1 ▶ if ($dump_type eq 'yaml') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dump_type eq "yaml") 0 1 1
67 0 return &{"$DumpModule\::Dump"}(@_) . "...\n";
68 }
69 1 ▶ if ($dump_type eq 'json') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dump_type eq "json") 0 1 1
70 0 return &{"$DumpModule\::encode_json"}(@_);
71 }
72 1 ▶ if ($dump_type eq 'dumper') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dump_type eq "dumper") 1 0 1
73 1 local $Data::Dumper::Sortkeys = 1;
74 1 local $Data::Dumper::Indent = 2;
75 1 return Data::Dumper::Dumper(@_);
76 }
77 0 ▶ if ($dump_type eq 'dump') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dump_type eq "dump") 0 0 0
78 0 return Data::Dump::dump(@_) . "\n";
79 }
80 0 ▶ if ($dump_type eq 'dumpcolor') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dump_type eq "dumpcolor") 0 0 0
81 0 return Data::Dump::Color::dump(@_) . "\n";
82 }
83 0 die "XXX had an internal error";
84 }
85  
86 sub _at_line_number {
87 3 ▶ my ($file_path, $line_number);
Subroutine _at_line_number: called CC=4 SCAR=14.3
88 3 my $caller = 0;
89 3 ▶ while (++$caller) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$caller) 3 0 3
90 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
91 3 my $skipper = (caller($caller))[0] . "::XXX_skip";
92 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
93 3 ($file_path, $line_number) = (caller($caller))[1,2];
94 3 last;
95 }
96 3 " at $file_path line $line_number\n";
97 }
98  
99 sub WWW {
100 0 ▶ my $dump = _xxx_dump(@_) . _at_line_number();
Subroutine WWW: not called CC=5 SCAR=34.0
Pod documented
101 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
102 defined &Test::More::diag and
103 \&main::diag eq \&Test::More::diag
104 ) {
105 0 main::diag($dump);
106 }
107 else {
108 0 warn($dump);
109 }
110 0 ▶ return wantarray ? @_ : $_[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
111 }
112  
113 sub XXX {
114 3 ▶ die _xxx_dump(@_) . _at_line_number();
Subroutine XXX: called CC=1 SCAR=0.0
Pod documented
115 }
116  
117 sub YYY {
118 0 ▶ my $dump = _xxx_dump(@_) . _at_line_number();
Subroutine YYY: not called CC=5 SCAR=34.0
Pod documented
119 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
120 defined &Test::More::note and
121 \&main::note eq \&Test::More::note
122 ) {
123 0 main::note($dump);
124 }
125 else {
126 0 print($dump);
127 }
128 0 ▶ return wantarray ? @_ : $_[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
129 }
130  
131 sub ZZZ {
132 0 ▶ require Carp;
Subroutine ZZZ: not called CC=1 SCAR=6.9
Pod documented
133 0 Carp::confess(_xxx_dump(@_));
134 }
135  
136 4 1;
↑ Summary