blib/lib/JSON/Meth.pm

filter: Statementstmt 97.5% 39 / 40 Branchbran 90.0% 9 / 10 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 3 / 3 Subroutinesub 100% 11 / 11 Podpod n/a totaltotal 97.1% 68 / 70 CC 8 SCAR 14.2
CC
8
Cov
96%
__ANON__
8.0
BEGIN
1.0
BEGIN
1.0
CRAP 4.1
↑ Summary
1 package JSON::Meth;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 6 our $VERSION = '1.001008'; # VERSION
7  
8 6 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use Scalar::Util qw/blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 require Exporter;
13 6 our @ISA = qw(Exporter);
14 6 our @EXPORT = qw($j);
15 6 our @EXPORT_OK = qw($json);
16  
17 6 my $data;
18  
19 3 ▶use overload q{""} => sub { $data },
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
20 1 ▶ q{@{}} => sub { $data },
Subroutine __ANON__: called CC=1 SCAR=0.0
21 6 ▶ q{%{}} => sub { $data };
Subroutine __ANON__: called CC=1 SCAR=0.0
22  
23 6 our ( $json, $j );
24 47 ▶$json = $j = bless sub {
Subroutine __ANON__: called CC=8 SCAR=20.8
25 47 my $in = shift;
26 47 ▶ return undef unless defined $in;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $in 1 46 47
27  
28 46 my $json_obj = JSON::MaybeXS->new(
29 convert_blessed => 1,
30 allow_blessed => 1,
31 );
32  
33 # plain data or object at root; just encode it
34 46 ▶ return $data = $json_obj->decode($in)
Branch: 1 branch
BranchTrueFalseTotal
if not ref $in or builtin::blessed($in) and builtin::blessed($in) ne "JSON::Meth" 22 24 46
Condition100%6/6
not ref $in or builtin::blessed($in) and builtin::blessed($in) ne "JSON::Meth"
l!l&&r!l&&!r
20224
builtin::blessed($in) and builtin::blessed($in) ne "JSON::Meth"
!ll&&!rl&&r
2222
MC/DC100%3/3
not ref $in or builtin::blessed($in) and builtin::blessed($in) ne "JSON::Meth"
not ref $in builtin::blessed($in) builtin::blessed($in) ne "JSON::Meth"
Truth table100%4/4
not(A) or B and C
A= not ref $inB= builtin::blessed($in)C= builtin::blessed($in) ne "JSON::Meth"
ABCresult
1XX1
0111
00X0
0100
35 if not ref $in
36 or ( blessed $in and blessed $in ne 'JSON::Meth' );
37  
38 24 ▶ return $data = $json_obj->encode($in)
Branch: 1 branch
BranchTrueFalseTotal
unless ref $in eq "JSON::Meth" 22 2 24
39 unless ref $in eq 'JSON::Meth';
40  
41 # if we got up to here, then we're dealing with a $j->$j call
42  
43 2 ▶ defined $data
Branch: 1 branch
BranchTrueFalseTotal
defined $data or croak("You tried to call \$j->\$j, but \$j does not have any data stored. You need at least one encode/decode call prior to this, for \$j->\$j to work.") 1 1 2
44 or croak 'You tried to call $j->$j, but $j does not have any data '
45 . ' stored. You need at least one encode/decode call prior to '
46 . ' this, for $j->$j to work.';
47  
48 1 ▶ return $data = $json_obj->decode($data)
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data 1 0 1
49 unless ref $data;
50  
51 0 return $data = $json_obj->encode($data);
52 6 }, __PACKAGE__;
53  
54 6 q{
55 Q: How many programmers does it take to change a light bulb?
56 A: None. It's a hardware problem.
57 };
58  
59 __END__
↑ Summary