line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Printer::Profile::JSON; |
2
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
863
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
sub profile { |
6
|
|
|
|
|
|
|
return { |
7
|
1
|
|
|
1
|
0
|
24
|
show_tainted => 0, |
8
|
|
|
|
|
|
|
show_unicode => 0, |
9
|
|
|
|
|
|
|
show_lvalue => 0, |
10
|
|
|
|
|
|
|
print_escapes => 0, |
11
|
|
|
|
|
|
|
scalar_quotes => q("), |
12
|
|
|
|
|
|
|
escape_chars => 'none', |
13
|
|
|
|
|
|
|
string_max => 0, |
14
|
|
|
|
|
|
|
unicode_charnames => 0, |
15
|
|
|
|
|
|
|
array_max => 0, |
16
|
|
|
|
|
|
|
index => 0, |
17
|
|
|
|
|
|
|
hash_max => 0, |
18
|
|
|
|
|
|
|
hash_separator => ': ', |
19
|
|
|
|
|
|
|
align_hash => 0, |
20
|
|
|
|
|
|
|
sort_keys => 0, |
21
|
|
|
|
|
|
|
quote_keys => 1, |
22
|
|
|
|
|
|
|
name => 'var', |
23
|
|
|
|
|
|
|
return_value => 'dump', |
24
|
|
|
|
|
|
|
output => 'stderr', |
25
|
|
|
|
|
|
|
indent => 2, |
26
|
|
|
|
|
|
|
show_readonly => 0, |
27
|
|
|
|
|
|
|
show_tied => 0, |
28
|
|
|
|
|
|
|
show_dualvar => 'off', |
29
|
|
|
|
|
|
|
show_weak => 0, |
30
|
|
|
|
|
|
|
show_refcount => 0, |
31
|
|
|
|
|
|
|
show_memsize => 0, |
32
|
|
|
|
|
|
|
separator => ',', |
33
|
|
|
|
|
|
|
end_separator => 0, |
34
|
|
|
|
|
|
|
caller_info => 0, |
35
|
|
|
|
|
|
|
colored => 0, |
36
|
|
|
|
|
|
|
class_method => undef, |
37
|
|
|
|
|
|
|
# Data::Printer doesn't provide a way to directly |
38
|
|
|
|
|
|
|
# decorate filters, so we do it ourselves: |
39
|
|
|
|
|
|
|
filters => [ |
40
|
|
|
|
|
|
|
{ |
41
|
|
|
|
|
|
|
'-class' => \&_json_class_filter, |
42
|
|
|
|
|
|
|
'SCALAR' => \&_json_scalar_filter, |
43
|
|
|
|
|
|
|
'LVALUE' => \&_json_scalar_filter, |
44
|
|
|
|
|
|
|
'CODE' => \&_json_code_filter, |
45
|
|
|
|
|
|
|
'FORMAT' => \&_json_format_filter, |
46
|
|
|
|
|
|
|
'GLOB' => \&_json_glob_filter, |
47
|
|
|
|
|
|
|
'REF' => \&_json_ref_filter,, |
48
|
|
|
|
|
|
|
'Regexp' => \&_json_regexp_filter, |
49
|
|
|
|
|
|
|
'VSTRING' => \&_json_vstring_filter, |
50
|
|
|
|
|
|
|
}, |
51
|
|
|
|
|
|
|
], |
52
|
|
|
|
|
|
|
}; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _json_class_filter { |
56
|
1
|
|
|
1
|
|
3
|
my ($obj, $ddp) = @_; |
57
|
1
|
|
|
|
|
5
|
Data::Printer::Common::_warn($ddp, 'json cannot express blessed objects. Showing internals only'); |
58
|
1
|
|
|
|
|
7
|
require Scalar::Util; |
59
|
1
|
|
|
|
|
4
|
my $reftype = Scalar::Util::reftype($obj); |
60
|
1
|
50
|
|
|
|
4
|
$reftype = 'Regexp' if $reftype eq 'REGEXP'; |
61
|
1
|
|
|
|
|
5
|
$ddp->indent; |
62
|
1
|
|
|
|
|
3
|
my $string = $ddp->parse_as($reftype, $obj); |
63
|
1
|
|
|
|
|
5
|
$ddp->outdent; |
64
|
1
|
|
|
|
|
3
|
return $string; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub _json_ref_filter { |
68
|
3
|
|
|
3
|
|
6
|
my ($ref, $ddp) = @_; |
69
|
3
|
|
|
|
|
7
|
my $reftype = ref $$ref; |
70
|
3
|
50
|
33
|
|
|
13
|
if ($reftype ne 'HASH' && $reftype ne 'ARRAY') { |
71
|
3
|
|
|
|
|
8
|
Data::Printer::Common::_warn($ddp, 'json cannot express references to scalars. Cast to non-reference'); |
72
|
|
|
|
|
|
|
} |
73
|
3
|
|
|
|
|
33
|
require Scalar::Util; |
74
|
3
|
|
|
|
|
11
|
my $id = pack 'J', Scalar::Util::refaddr($$ref); |
75
|
3
|
100
|
|
|
|
9
|
if ($ddp->seen($$ref)) { |
76
|
2
|
|
|
|
|
7
|
Data::Printer::Common::_warn($ddp, 'json cannot express circular references. Cast to string'); |
77
|
2
|
|
|
|
|
8
|
return '"' . $ddp->parse($$ref) . '"'; |
78
|
|
|
|
|
|
|
} |
79
|
1
|
|
|
|
|
5
|
return $ddp->parse($$ref); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub _json_glob_filter { |
83
|
1
|
|
|
1
|
|
3
|
my (undef, $ddp) = @_; |
84
|
1
|
|
|
|
|
4
|
Data::Printer::Common::_warn($ddp, 'json cannot express globs.'); |
85
|
1
|
|
|
|
|
5
|
return ''; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub _json_format_filter { |
89
|
1
|
|
|
1
|
|
6
|
my $res = Data::Printer::Filter::FORMAT::parse(@_); |
90
|
1
|
|
|
|
|
5
|
return '"' . $res . '"'; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _json_regexp_filter { |
94
|
1
|
|
|
1
|
|
3
|
my ($re, $ddp) = @_; |
95
|
1
|
|
|
|
|
5
|
Data::Printer::Common::_warn($ddp, 'regular expression cast to string (flags removed)'); |
96
|
1
|
|
|
|
|
4
|
my $v = "$re"; |
97
|
1
|
|
|
|
|
3
|
my $mod = ""; |
98
|
1
|
50
|
|
|
|
7
|
if ($v =~ /^\(\?\^?([msixpadlun-]*):([\x00-\xFF]*)\)\z/) { |
99
|
1
|
|
|
|
|
4
|
$mod = $1; |
100
|
1
|
|
|
|
|
3
|
$v = $2; |
101
|
1
|
|
|
|
|
2
|
$mod =~ s/-.*//; |
102
|
|
|
|
|
|
|
} |
103
|
1
|
|
|
|
|
3
|
$v =~ s{/}{\\/}g; |
104
|
1
|
|
|
|
|
6
|
return '"' . "/$v/$mod" . '"'; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub _json_vstring_filter { |
108
|
1
|
|
|
1
|
|
3
|
my ($scalar, $ddp) = @_; |
109
|
1
|
|
|
|
|
4
|
Data::Printer::Common::_warn($ddp, 'json cannot express vstrings. Cast to string'); |
110
|
1
|
|
|
|
|
5
|
my $ret = Data::Printer::Filter::VSTRING::parse(@_); |
111
|
1
|
|
|
|
|
5
|
return '"' . $ret . '"'; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub _json_scalar_filter { |
115
|
6
|
|
|
6
|
|
13
|
my ($scalar, $ddp) = @_; |
116
|
6
|
100
|
|
|
|
18
|
return $ddp->maybe_colorize('null', 'undef') if !defined $$scalar; |
117
|
5
|
|
|
|
|
15
|
return Data::Printer::Filter::SCALAR::parse(@_); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub _json_code_filter { |
121
|
1
|
|
|
1
|
|
3
|
my (undef, $ddp) = @_; |
122
|
1
|
|
|
|
|
4
|
Data::Printer::Common::_warn($ddp, 'json cannot express subroutines. Cast to string'); |
123
|
1
|
|
|
|
|
7
|
my $res = Data::Printer::Filter::CODE::parse(@_); |
124
|
1
|
|
|
|
|
5
|
return '"' . $res . '"'; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |
128
|
|
|
|
|
|
|
__END__ |