line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Printer::Filter::SCALAR; |
2
|
32
|
|
|
32
|
|
231
|
use strict; |
|
32
|
|
|
|
|
61
|
|
|
32
|
|
|
|
|
901
|
|
3
|
32
|
|
|
32
|
|
146
|
use warnings; |
|
32
|
|
|
|
|
58
|
|
|
32
|
|
|
|
|
731
|
|
4
|
32
|
|
|
32
|
|
12132
|
use Data::Printer::Filter; |
|
32
|
|
|
|
|
71
|
|
|
32
|
|
|
|
|
211
|
|
5
|
32
|
|
|
32
|
|
187
|
use Scalar::Util; |
|
32
|
|
|
|
|
53
|
|
|
32
|
|
|
|
|
4745
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
filter 'SCALAR' => \&parse; |
8
|
|
|
|
|
|
|
filter 'LVALUE' => sub { |
9
|
|
|
|
|
|
|
my ($scalar_ref, $ddp) = @_; |
10
|
|
|
|
|
|
|
my $string = parse($scalar_ref, $ddp); |
11
|
|
|
|
|
|
|
if ($ddp->show_lvalue) { |
12
|
|
|
|
|
|
|
$string .= $ddp->maybe_colorize(' (LVALUE)', 'lvalue'); |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
return $string; |
15
|
|
|
|
|
|
|
}; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub parse { |
18
|
314
|
|
|
314
|
0
|
607
|
my ($scalar_ref, $ddp) = @_; |
19
|
|
|
|
|
|
|
|
20
|
314
|
|
|
|
|
479
|
my $ret; |
21
|
314
|
50
|
|
|
|
871
|
my $value = ref $scalar_ref ? $$scalar_ref : $scalar_ref; |
22
|
|
|
|
|
|
|
|
23
|
314
|
100
|
|
|
|
1182
|
if (not defined $value) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
24
|
19
|
|
|
|
|
65
|
$ret = $ddp->maybe_colorize('undef', 'undef'); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
elsif ( $ddp->show_dualvar ne 'off' ) { |
27
|
285
|
|
|
|
|
442
|
my $numified; |
28
|
32
|
50
|
|
32
|
|
197
|
$numified = do { no warnings 'numeric'; 0+ $value } if defined $value; |
|
32
|
|
|
|
|
74
|
|
|
32
|
|
|
|
|
19750
|
|
|
285
|
|
|
|
|
650
|
|
|
285
|
|
|
|
|
792
|
|
29
|
285
|
100
|
66
|
|
|
859
|
if ( $numified ) { |
|
|
100
|
|
|
|
|
|
30
|
218
|
100
|
100
|
|
|
881
|
if ( "$numified" eq $value |
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
31
|
|
|
|
|
|
|
|| ( |
32
|
|
|
|
|
|
|
# lax mode allows decimal zeroes |
33
|
|
|
|
|
|
|
$ddp->show_dualvar eq 'lax' |
34
|
|
|
|
|
|
|
&& ((index("$numified",'.') != -1 && $value =~ /\A\s*${numified}[0]*\s*\z/) |
35
|
|
|
|
|
|
|
|| (index("$numified",'.') == -1 && $value =~ /\A\s*$numified(?:\.[0]*)?\s*\z/)) |
36
|
|
|
|
|
|
|
) |
37
|
|
|
|
|
|
|
) { |
38
|
206
|
|
|
|
|
625
|
$value =~ s/\A\s+//; |
39
|
206
|
|
|
|
|
472
|
$value =~ s/\s+\z//; |
40
|
206
|
|
|
|
|
537
|
$ret = $ddp->maybe_colorize($value, 'number'); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
else { |
43
|
12
|
|
|
|
|
95
|
$ret = Data::Printer::Common::_process_string( $ddp, "$value", 'string' ); |
44
|
12
|
|
|
|
|
64
|
$ret = _quoteme($ddp, $ret); |
45
|
12
|
|
|
|
|
54
|
$ret .= ' (dualvar: ' . $ddp->maybe_colorize( $numified, 'number' ) . ')'; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
elsif ( !$numified && _is_number($value) ) { |
49
|
8
|
|
|
|
|
41
|
$ret = $ddp->maybe_colorize($value, 'number'); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
else { |
52
|
59
|
|
|
|
|
246
|
$ret = Data::Printer::Common::_process_string($ddp, $value, 'string'); |
53
|
59
|
|
|
|
|
238
|
$ret = _quoteme($ddp, $ret); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
elsif (_is_number($value)) { |
57
|
6
|
|
|
|
|
15
|
$ret = $ddp->maybe_colorize($value, 'number'); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
else { |
60
|
4
|
|
|
|
|
15
|
$ret = Data::Printer::Common::_process_string($ddp, $value, 'string'); |
61
|
4
|
|
|
|
|
13
|
$ret = _quoteme($ddp, $ret); |
62
|
|
|
|
|
|
|
} |
63
|
314
|
|
|
|
|
838
|
$ret .= _check_tainted($ddp, $scalar_ref); |
64
|
314
|
|
|
|
|
827
|
$ret .= _check_unicode($ddp, $scalar_ref); |
65
|
|
|
|
|
|
|
|
66
|
314
|
100
|
100
|
|
|
806
|
if ($ddp->show_tied and my $tie = ref tied $$scalar_ref) { |
67
|
1
|
|
|
|
|
4
|
$ret .= " (tied to $tie)"; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
314
|
|
|
|
|
1132
|
return $ret; |
71
|
|
|
|
|
|
|
}; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
####################################### |
74
|
|
|
|
|
|
|
### Private auxiliary helpers below ### |
75
|
|
|
|
|
|
|
####################################### |
76
|
|
|
|
|
|
|
sub _quoteme { |
77
|
75
|
|
|
75
|
|
191
|
my ($ddp, $text) = @_; |
78
|
|
|
|
|
|
|
|
79
|
75
|
|
|
|
|
209
|
my $scalar_quotes = $ddp->scalar_quotes; |
80
|
75
|
50
|
|
|
|
206
|
if (defined $scalar_quotes) { |
81
|
|
|
|
|
|
|
# foo'bar ==> 'foo\'bar' |
82
|
75
|
50
|
|
|
|
334
|
$text =~ s{$scalar_quotes}{\\$scalar_quotes}g if index($text, $scalar_quotes) >= 0; |
83
|
75
|
|
|
|
|
241
|
my $quote = $ddp->maybe_colorize( $scalar_quotes, 'quotes' ); |
84
|
75
|
|
|
|
|
291
|
$text = $quote . $text . $quote; |
85
|
|
|
|
|
|
|
} |
86
|
75
|
|
|
|
|
206
|
return $text; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub _check_tainted { |
90
|
314
|
|
|
314
|
|
606
|
my ($self, $var) = @_; |
91
|
314
|
100
|
100
|
|
|
837
|
return ' (TAINTED)' if $self->show_tainted && Scalar::Util::tainted($$var); |
92
|
311
|
|
|
|
|
832
|
return ''; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub _check_unicode { |
96
|
314
|
|
|
314
|
|
616
|
my ($self, $var) = @_; |
97
|
314
|
100
|
100
|
|
|
709
|
return ' (U)' if $self->show_unicode && utf8::is_utf8($$var); |
98
|
313
|
|
|
|
|
626
|
return ''; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _is_number { |
102
|
77
|
|
|
77
|
|
218
|
my ($maybe_a_number) = @_; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# Scalar values that start with a zero are strings, NOT numbers. |
105
|
|
|
|
|
|
|
# You can write `my $foo = 0123`, but then `$foo` will be 83, |
106
|
|
|
|
|
|
|
# (numbers starting with zero are octal integers) |
107
|
77
|
50
|
|
|
|
306
|
return if $maybe_a_number =~ /^-?0[0-9]/; |
108
|
|
|
|
|
|
|
|
109
|
77
|
|
|
|
|
378
|
my $is_number = $maybe_a_number =~ m/ |
110
|
|
|
|
|
|
|
^ |
111
|
|
|
|
|
|
|
-? # numbers may begin with a '-' sign, but can't with a '+'. |
112
|
|
|
|
|
|
|
# If they do they are not numbers, but strings. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
[0-9]+ # then there should be some numbers |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
( \. [0-9]+ )? # there can be decimal part, which is optional |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
( e [+-] [0-9]+ )? # and an also optional exponential notation part |
119
|
|
|
|
|
|
|
\z |
120
|
|
|
|
|
|
|
/x; |
121
|
|
|
|
|
|
|
|
122
|
77
|
|
|
|
|
333
|
return $is_number; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
1; |