Data/Printer/Filter/SCALAR.pm

filter: Statementstmt 100% 77 / 77 Branchbran 85.2% 29 / 34 Conditioncond 88.8% 24 / 27 MC/DCmcdc 78.5% 11 / 14 Subroutinesub 100% 14 / 14 Podpod 0.0% 0 / 1 totaltotal 92.8% 155 / 167 CC 27 SCAR 23.2
CC
27
Cov
94%
parse
19.1
_quoteme
3.1
_check_tainted
3.0
CRAP 10.2
« Data/Printer.pm ↑ Summary Data/Printer/Filter/Web.pm »
1 package Data::Printer::Filter::SCALAR;
2 35 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 35 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 35 ▶use Data::Printer::Filter;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 35 ▶use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 35 ▶use constant HAS_BOOLEAN => $] ge '5.036000';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 35 filter 'SCALAR' => \&parse;
10 2 ▶filter 'LVALUE' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
11 2 my ($scalar_ref, $ddp) = @_;
12 2 my $string = parse($scalar_ref, $ddp);
13 2 ▶ if ($ddp->show_lvalue) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ddp->show_lvalue) 1 1 2
14 1 $string .= $ddp->maybe_colorize(' (LVALUE)', 'lvalue');
15 }
16 2 return $string;
17 35 };
18  
19 328 ▶sub parse {
Subroutine parse: called CC=19 SCAR=29.5
Pod undocumented
20 328 my ($scalar_ref, $ddp) = @_;
21  
22 328 my $ret;
23 328 ▶ my $value = ref $scalar_ref ? $$scalar_ref : $scalar_ref;
Branch: 1 branch
BranchTrueFalseTotal
ref $scalar_ref ? : 328 0 328
24  
25 328 ▶ if (not defined $value) {
Branch: 4 branches
BranchTrueFalseTotal
if (not defined $value) { } 21 307 328
elsif (_is_bool($value)) { } 2 305 307
elsif ($ddp->show_dualvar ne 'off') { } 295 10 305
elsif (_is_number($value)) { } 6 4 10
26 21 $ret = $ddp->maybe_colorize('undef', 'undef');
27 }
28 elsif (HAS_BOOLEAN && _is_bool($value)) {
29 2 ▶ if ($value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value) { } 1 1 2
30 1 $ret = $ddp->maybe_colorize('true', 'true');
31 } else {
32 1 $ret = $ddp->maybe_colorize('false', 'false');
33 }
34 }
35 elsif ( $ddp->show_dualvar ne 'off' ) {
36 295 my $numified;
37 35 ▶ $numified = do { no warnings 'numeric'; 0+ $value } if defined $value;
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 295 0 295
38 295 ▶ if ( $numified ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($numified) { } 220 75 295
elsif (not $numified and _is_number($value)) { } 9 66 75
39 220 ▶ if ( "$numified" eq $value
Branch: 1 branch
BranchTrueFalseTotal
if ("$numified" eq $value or $ddp->show_dualvar eq 'lax' and index("$numified", '.') != -1 && $value =~ /\A\s*${numified}[0]*\s*\z/ || index("$numified", '.') == -1 && $value =~ /\A\s*$numified(?:\.[0]*)?\s*\z/) { } 208 12 220
Condition86%13/15
"$numified" eq $value or $ddp->show_dualvar eq "lax" and index("$numified", ".") != -1 && $value =~ /\A\s*${numified}[0]*\s*\z/ || index("$numified", ".") == -1 && $value =~ /\A\s*$numified(?:\.[0]*)?\s*\z/
l!l&&r!l&&!r
202612
$ddp->show_dualvar eq "lax" and index("$numified", ".") != -1 && $value =~ /\A\s*${numified}[0]*\s*\z/ || index("$numified", ".") == -1 && $value =~ /\A\s*$numified(?:\.[0]*)?\s*\z/
!ll&&!rl&&r
936
index("$numified", ".") != -1 and $value =~ /\A\s*${numified}[0]*\s*\z/ or index("$numified", ".") == -1 and $value =~ /\A\s*$numified(?:\.[0]*)?\s*\z/
l!l&&r!l&&!r
333
index("$numified", ".") != -1 and $value =~ /\A\s*${numified}[0]*\s*\z/
!ll&&!rl&&r
603
index("$numified", ".") == -1 and $value =~ /\A\s*$numified(?:\.[0]*)?\s*\z/
!ll&&!rl&&r
033
MC/DC66%4/6
"$numified" eq $value or $ddp->show_dualvar eq "lax" and index("$numified", ".") != -1 && $value =~ /\A\s*${numified}[0]*\s*\z/ || index("$numified", ".") == -1 && $value =~ /\A\s*$numified(?:\.[0]*)?\s*\z/
"$numified" eq $value $ddp->show_dualvar eq "lax" index("$numified", ".") != -1 $value =~ /\A\s*${numified}[0]*\s*\z/ index("$numified", ".") == -1 $value =~ /\A\s*$numified(?:\.[0]*)?\s*\z/
Truth table55%5/9
A or B and C and D or E and F
A= "$numified" eq $valueB= $ddp->show_dualvar eq "lax"C= index("$numified", ".") != -1D= $value =~ /\A\s*${numified}[0]*\s*\z/E= index("$numified", ".") == -1F= $value =~ /\A\s*$numified(?:\.[0]*)?\s*\z/
ABCDEFresult
1XXXXX1
0111XX1
010X111
0110111
00XXXX0
010X0X0
010X100
01100X0
0110100
40 || (
41 # lax mode allows decimal zeroes
42 $ddp->show_dualvar eq 'lax'
43 && ((index("$numified",'.') != -1 && $value =~ /\A\s*${numified}[0]*\s*\z/)
44 || (index("$numified",'.') == -1 && $value =~ /\A\s*$numified(?:\.[0]*)?\s*\z/))
45 )
46 ) {
47 208 $value =~ s/\A\s+//;
48 208 $value =~ s/\s+\z//;
49 208 $ret = $ddp->maybe_colorize($value, 'number');
50 }
51 else {
52 12 $ret = Data::Printer::Common::_process_string( $ddp, "$value", 'string' );
53 12 $ret = _quoteme($ddp, $ret);
54 12 $ret .= ' (dualvar: ' . $ddp->maybe_colorize( $numified, 'number' ) . ')';
55 }
56 }
57 ▶ elsif ( !$numified && _is_number($value) ) {
Condition66%2/3
not $numified and _is_number($value)
!ll&&!rl&&r
0669
MC/DC50%1/2
not $numified and _is_number($value)
not $numified _is_number($value)
Truth table66%2/3
not(A) and B
A= not $numifiedB= _is_number($value)
ABresult
0X0
100
111
58 9 $ret = $ddp->maybe_colorize($value, 'number');
59 }
60 else {
61 66 $ret = Data::Printer::Common::_process_string($ddp, $value, 'string');
62 66 $ret = _quoteme($ddp, $ret);
63 }
64 }
65 elsif (_is_number($value)) {
66 6 $ret = $ddp->maybe_colorize($value, 'number');
67 }
68 else {
69 4 $ret = Data::Printer::Common::_process_string($ddp, $value, 'string');
70 4 $ret = _quoteme($ddp, $ret);
71 }
72 328 $ret .= _check_tainted($ddp, $scalar_ref);
73 328 $ret .= _check_unicode($ddp, $scalar_ref);
74  
75 328 ▶ if ($ddp->show_tied and my $tie = ref tied $$scalar_ref) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ddp->show_tied and my $tie = ref tied $$scalar_ref) 1 327 328
Condition100%3/3
$ddp->show_tied and my $tie = ref tied $$scalar_ref
!ll&&!rl&&r
143131
MC/DC100%2/2
$ddp->show_tied and my $tie = ref tied $$scalar_ref
$ddp->show_tied my $tie = ref tied $$scalar_ref
Truth table100%3/3
A and B
A= $ddp->show_tiedB= my $tie = ref tied $$scalar_ref
ABresult
0X0
100
111
76 1 $ret .= " (tied to $tie)";
77 }
78  
79 328 return $ret;
80 };
81  
82 #######################################
83 ### Private auxiliary helpers below ###
84 #######################################
85 82 ▶sub _quoteme {
Subroutine _quoteme: called CC=3 SCAR=11.2
86 82 my ($ddp, $text) = @_;
87  
88 82 my $scalar_quotes = $ddp->scalar_quotes;
89 82 ▶ if (defined $scalar_quotes) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $scalar_quotes) 82 0 82
90 # foo'bar ==> 'foo\'bar'
91 82 ▶ $text =~ s{$scalar_quotes}{\\$scalar_quotes}g if index($text, $scalar_quotes) >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($text, $scalar_quotes) != -1 0 82 82
92 82 my $quote = $ddp->maybe_colorize( $scalar_quotes, 'quotes' );
93 82 $text = $quote . $text . $quote;
94 }
95 82 return $text;
96 }
97  
98 328 ▶sub _check_tainted {
Subroutine _check_tainted: called CC=3 SCAR=11.0
99 328 my ($self, $var) = @_;
100 328 ▶ return ' (TAINTED)' if $self->show_tainted && Scalar::Util::tainted($$var);
Branch: 1 branch
BranchTrueFalseTotal
if $self->show_tainted and &Scalar::Util::tainted($$var) 3 325 328
Condition100%3/3
$self->show_tainted and &Scalar::Util::tainted($$var)
!ll&&!rl&&r
113143
MC/DC100%2/2
$self->show_tainted and &Scalar::Util::tainted($$var)
$self->show_tainted &Scalar::Util::tainted($$var)
Truth table100%3/3
A and B
A= $self->show_taintedB= &Scalar::Util::tainted($$var)
ABresult
0X0
100
111
101 325 return '';
102 }
103  
104 328 ▶sub _check_unicode {
Subroutine _check_unicode: called CC=3 SCAR=11.0
105 328 my ($self, $var) = @_;
106 328 ▶ return ' (U)' if $self->show_unicode && utf8::is_utf8($$var);
Branch: 1 branch
BranchTrueFalseTotal
if $self->show_unicode and utf8::is_utf8($$var) 1 327 328
Condition100%3/3
$self->show_unicode and utf8::is_utf8($$var)
!ll&&!rl&&r
32611
MC/DC100%2/2
$self->show_unicode and utf8::is_utf8($$var)
$self->show_unicode utf8::is_utf8($$var)
Truth table100%3/3
A and B
A= $self->show_unicodeB= utf8::is_utf8($$var)
ABresult
0X0
100
111
107 327 return '';
108 }
109  
110 85 ▶sub _is_number {
Subroutine _is_number: called CC=2 SCAR=7.0
111 85 my ($maybe_a_number) = @_;
112  
113 # Scalar values that start with a zero are strings, NOT numbers.
114 # You can write `my $foo = 0123`, but then `$foo` will be 83,
115 # (numbers starting with zero are octal integers)
116 85 ▶ return if $maybe_a_number =~ /^-?0[0-9]/;
Branch: 1 branch
BranchTrueFalseTotal
if $maybe_a_number =~ /^-?0[0-9]/ 0 85 85
117  
118 85 my $is_number = $maybe_a_number =~ m/
119 ^
120 -? # numbers may begin with a '-' sign, but can't with a '+'.
121 # If they do they are not numbers, but strings.
122  
123 [0-9]+ # then there should be some numbers
124  
125 ( \. [0-9]+ )? # there can be decimal part, which is optional
126  
127 ( e [+-] [0-9]+ )? # and an also optional exponential notation part
128 \z
129 /x;
130  
131 85 return $is_number;
132 }
133  
134 307 ▶sub _is_bool {
Subroutine _is_bool: called CC=1 SCAR=0.0
135 35 ▶ no if HAS_BOOLEAN, warnings => 'experimental::builtin';
Subroutine BEGIN: called CC=1 SCAR=0.0
136 307 return builtin::is_bool($_[0]);
137 }
138  
139  
140 35 1;
« Data/Printer.pm ↑ Summary Data/Printer/Filter/Web.pm »