Data/Printer/Profile/JSON.pm

filter: Statementstmt 100% 53 / 53 Branchbran 70.0% 7 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 1 totaltotal 90.0% 72 / 80 CC 7 SCAR 7.3
CC
7
Cov
92%
_json_ref_filter
4.1
_json_class_filter
2.0
_json_regexp_filter
2.0
CRAP 2.1
« Data/Printer/Filter.pm ↑ Summary Data/Printer/Common.pm »
1 package Data::Printer::Profile::JSON;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶sub profile {
Subroutine profile: called CC=1 SCAR=0.0
Pod undocumented
6 return {
7 1 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 1 ▶sub _json_class_filter {
Subroutine _json_class_filter: called CC=2 SCAR=6.9
56 1 my ($obj, $ddp) = @_;
57 1 Data::Printer::Common::_warn($ddp, 'json cannot express blessed objects. Showing internals only');
58 1 require Scalar::Util;
59 1 my $reftype = Scalar::Util::reftype($obj);
60 1 ▶ $reftype = 'Regexp' if $reftype eq 'REGEXP';
Branch: 1 branch
BranchTrueFalseTotal
if $reftype eq "REGEXP" 0 1 1
61 1 $ddp->indent;
62 1 my $string = $ddp->parse_as($reftype, $obj);
63 1 $ddp->outdent;
64 1 return $string;
65 }
66  
67 3 ▶sub _json_ref_filter {
Subroutine _json_ref_filter: called CC=4 SCAR=14.1
68 3 my ($ref, $ddp) = @_;
69 3 my $reftype = ref $$ref;
70 3 ▶ if ($reftype ne 'HASH' && $reftype ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($reftype ne "HASH" and $reftype ne "ARRAY") 3 0 3
Condition33%1/3
$reftype ne "HASH" and $reftype ne "ARRAY"
!ll&&!rl&&r
003
MC/DC0%0/2
$reftype ne "HASH" and $reftype ne "ARRAY"
$reftype ne "HASH" $reftype ne "ARRAY"
Truth table33%1/3
A and B
A= $reftype ne "HASH"B= $reftype ne "ARRAY"
ABresult
0X0
100
111
71 3 Data::Printer::Common::_warn($ddp, 'json cannot express references to scalars. Cast to non-reference');
72 }
73 3 require Scalar::Util;
74 3 my $id = pack 'J', Scalar::Util::refaddr($$ref);
75 3 ▶ if ($ddp->seen($$ref)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ddp->seen($$ref)) 2 1 3
76 2 Data::Printer::Common::_warn($ddp, 'json cannot express circular references. Cast to string');
77 2 return '"' . $ddp->parse($$ref) . '"';
78 }
79 1 return $ddp->parse($$ref);
80 }
81  
82 1 ▶sub _json_glob_filter {
Subroutine _json_glob_filter: called CC=1 SCAR=0.0
83 1 my (undef, $ddp) = @_;
84 1 Data::Printer::Common::_warn($ddp, 'json cannot express globs.');
85 1 return '';
86 }
87  
88 1 ▶sub _json_format_filter {
Subroutine _json_format_filter: called CC=1 SCAR=0.0
89 1 my $res = Data::Printer::Filter::FORMAT::parse(@_);
90 1 return '"' . $res . '"';
91 }
92  
93 1 ▶sub _json_regexp_filter {
Subroutine _json_regexp_filter: called CC=2 SCAR=6.9
94 1 my ($re, $ddp) = @_;
95 1 Data::Printer::Common::_warn($ddp, 'regular expression cast to string (flags removed)');
96 1 my $v = "$re";
97 1 my $mod = "";
98 1 ▶ if ($v =~ /^\(\?\^?([msixpadlun-]*):([\x00-\xFF]*)\)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ /^\(\?\^?([msixpadlun-]*):([\x00-\xFF]*)\)\z/) 1 0 1
99 1 $mod = $1;
100 1 $v = $2;
101 1 $mod =~ s/-.*//;
102 }
103 1 $v =~ s{/}{\\/}g;
104 1 return '"' . "/$v/$mod" . '"';
105 }
106  
107 1 ▶sub _json_vstring_filter {
Subroutine _json_vstring_filter: called CC=1 SCAR=0.0
108 1 my ($scalar, $ddp) = @_;
109 1 Data::Printer::Common::_warn($ddp, 'json cannot express vstrings. Cast to string');
110 1 my $ret = Data::Printer::Filter::VSTRING::parse(@_);
111 1 return '"' . $ret . '"';
112 }
113  
114 6 ▶sub _json_scalar_filter {
Subroutine _json_scalar_filter: called CC=2 SCAR=6.9
115 6 my ($scalar, $ddp) = @_;
116 6 ▶ return $ddp->maybe_colorize('null', 'undef') if !defined $$scalar;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$scalar 1 5 6
117 5 return Data::Printer::Filter::SCALAR::parse(@_);
118 }
119  
120 1 ▶sub _json_code_filter {
Subroutine _json_code_filter: called CC=1 SCAR=0.0
121 1 my (undef, $ddp) = @_;
122 1 Data::Printer::Common::_warn($ddp, 'json cannot express subroutines. Cast to string');
123 1 my $res = Data::Printer::Filter::CODE::parse(@_);
124 1 return '"' . $res . '"';
125 }
126  
127 1 1;
128 __END__
« Data/Printer/Filter.pm ↑ Summary Data/Printer/Common.pm »