| 1 | package JSON::YY; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 29 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 29 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 29 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 29 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 29 | our $VERSION = '0.08'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 29 | require XSLoader; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 29 | XSLoader::load('JSON::YY', $VERSION); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 29 | our @EXPORT_OK = qw(encode_json decode_json decode_json_ro is_bool true false); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # JSON::PP assigns $JSON::PP::true/false when it loads, so load it before | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # handing them out: loaded later, it would replace the objects already given. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | ▶ | sub true { require JSON::PP; $JSON::PP::true } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
true: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | sub false { require JSON::PP; $JSON::PP::false } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
false: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 6 | ▶ | sub is_bool { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_bool: called CC=10 SCAR=26.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 6 | my ($val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 6 | ▶ | return 0 unless defined $val; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 5 | ▶ | if (Scalar::Util::blessed($val)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | return 1 if eval { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | ▶ | $val->isa('JSON::PP::Boolean') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%4/12
$val->isa('JSON::PP::Boolean') || $val->isa('boolean') || $val->isa('Types::Serialiser::BooleanBase') || $val->isa('Types::Serialiser::Boolean') || $val->isa('JSON::XS::Boolean')
$val->isa("JSON::PP::Boolean") or $val->isa("boolean") or $val->isa("Types::Serialiser::BooleanBase") or $val->isa("Types::Serialiser::Boolean")
$val->isa("JSON::PP::Boolean") or $val->isa("boolean") or $val->isa("Types::Serialiser::BooleanBase")
$val->isa("JSON::PP::Boolean") or $val->isa("boolean")
MC/DC0%0/5
$val->isa('JSON::PP::Boolean') || $val->isa('boolean') || $val->isa('Types::Serialiser::BooleanBase') || $val->isa('Types::Serialiser::Boolean') || $val->isa('JSON::XS::Boolean')
$val->isa("JSON::PP::Boolean")
$val->isa("boolean")
$val->isa("Types::Serialiser::BooleanBase")
$val->isa("Types::Serialiser::Boolean")
$val->isa('JSON::XS::Boolean')
Truth table16%1/6
A or B or C or D || E
A= $val->isa("JSON::PP::Boolean")B= $val->isa("boolean")C= $val->isa("Types::Serialiser::BooleanBase")D= $val->isa("Types::Serialiser::Boolean")E= $val->isa('JSON::XS::Boolean')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | || $val->isa('boolean') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | || $val->isa('Types::Serialiser::BooleanBase') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | || $val->isa('Types::Serialiser::Boolean') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | || $val->isa('JSON::XS::Boolean') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 3 | ▶ | if (defined &builtin::is_bool) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 29 | ▶ | no if $] >= 5.036, warnings => 'experimental::builtin'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 3 | ▶ | return 1 if builtin::is_bool($val); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 29 | my @DOC_KEYWORDS = qw(jdoc jget jgetp jset jdel jhas jclone jencode | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | jstr jnum jbool jnull jarr jobj jtype jlen jkeys jdecode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | jiter jnext jkey jpatch jmerge jfrom jvals jeq | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | jpp jraw jread jwrite jpaths jfind | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | jis_obj jis_arr jis_str jis_num jis_int jis_real jis_bool jis_null); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # functional API — fast XS path, always utf8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 29 | *encode_json = \&_xs_encode_json; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 29 | *decode_json = \&_xs_decode_json; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 29 | *decode_json_ro = \&_xs_decode_json_ro; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # max_depth reaches XS as a U32: -1 would wrap to 4294967295, which is not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # "unlimited" but "deep enough to blow the C stack". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 21 | ▶ | sub _checked_max_depth { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_checked_max_depth: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 21 | my ($self, $val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 21 | ▶ | $val = 512 unless defined $val; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 21 | ▶ | Carp::croak("max_depth must be a non-negative integer (got '$val')") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$val =~ /\A[0-9]+\z/ and $val <= 4294967295
MC/DC100%2/2
$val =~ /\A[0-9]+\z/ and $val <= 4294967295
$val =~ /\A[0-9]+\z/
$val <= 4294967295
Truth table100%3/3
A and B
A= $val =~ /\A[0-9]+\z/B= $val <= 4294967295
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | unless $val =~ /\A[0-9]+\z/ && $val <= 0xFFFFFFFF; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 11 | $self->_set_max_depth($val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 13 | ▶ | sub _checked_bool { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_checked_bool: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 13 | my ($self, $val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 13 | ▶ | require JSON::PP if $val; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 13 | $self->_set_bool($val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 29 | my %SETTERS = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | utf8 => \&_set_utf8, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | pretty => \&_set_pretty, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | canonical => \&_set_canonical, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | allow_nonref => \&_set_allow_nonref, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | allow_unknown => \&_set_allow_unknown, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | allow_blessed => \&_set_allow_blessed, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | convert_blessed => \&_set_convert_blessed, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | max_depth => \&_checked_max_depth, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | bool => \&_checked_bool, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | boolean => \&_checked_bool, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | boolean_object => \&_checked_bool, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 49 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=16 SCAR=28.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 49 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 49 | my @exports; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | my @flags; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 49 | my $want_doc = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 49 | for my $arg (@_) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 73 | ▶ | if ($arg eq ':doc') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 19 | $want_doc = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } elsif ($arg =~ /^-(.+)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 8 | push @flags, $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 46 | push @exports, $arg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 49 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | # activate keywords via XS::Parse::Keyword hint keys | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 49 | ▶ | if ($want_doc) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 19 | $^H{"JSON::YY/$_"} = 1 for @DOC_KEYWORDS; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 49 | ▶ | if (@flags) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 6 | my $coder = $class->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 6 | for my $f (@flags) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 8 | ▶ | my $setter = $SETTERS{$f} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | or Carp::croak("unknown flag: -$f"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 8 | $coder->$setter(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 29 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 29 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # a qw() import in the same scope leaves the keyword hint set, and the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # compiler would then bypass these closures entirely -- silently | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | # dropping the flags the caller just asked for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 6 | delete $^H{"JSON::YY/$_"} for qw(encode_json decode_json); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 6 | ▶ | *{"${caller}::encode_json"} = sub { $coder->encode($_[0]) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 6 | ▶ | *{"${caller}::decode_json"} = sub { $coder->decode($_[0]) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 49 | ▶ | if (@exports) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 29 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 24 | for my $e (@exports) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | Carp::croak("'$e' is not exported by JSON::YY") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 46 | ▶ | unless grep { $_ eq $e } @EXPORT_OK; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 46 | ▶ | next if @flags && ($e eq 'encode_json' || $e eq 'decode_json'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition16%1/6
@flags and $e eq "encode_json" || $e eq "decode_json"
$e eq "encode_json" or $e eq "decode_json"
MC/DC0%0/3
@flags and $e eq "encode_json" || $e eq "decode_json"
@flags
$e eq "encode_json"
$e eq "decode_json"
Truth table25%1/4
A and B or C
A= @flagsB= $e eq "encode_json"C= $e eq "decode_json"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 46 | *{"${caller}::$e"} = \&{$e}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | # also enable keyword for exported functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 46 | $^H{"JSON::YY/$e"} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # chaining setters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 10 | ▶ | sub utf8 { $_[0]->_set_utf8($_[1] // 1); $_[0] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
utf8: called CC=2 SCAR=7.2
Pod
documented
Condition50%1/2
$_[1] // 1
MC/DC0%0/1
$_[1] // 1
$_[1]
Truth table50%1/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 3 | ▶ | sub pretty { $_[0]->_set_pretty($_[1] // 1); $_[0] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pretty: called CC=2 SCAR=7.2
Pod
documented
Condition50%1/2
$_[1] // 1
MC/DC0%0/1
$_[1] // 1
$_[1]
Truth table50%1/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | sub canonical { $_[0]->_set_canonical($_[1] // 1); $_[0] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
canonical: not called CC=2 SCAR=17.9
Pod
documented
Condition0%0/2
$_[1] // 1
MC/DC0%0/1
$_[1] // 1
$_[1]
Truth table0%0/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 3 | ▶ | sub allow_nonref { $_[0]->_set_allow_nonref($_[1] // 1); $_[0] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
allow_nonref: called CC=2 SCAR=6.9
Pod
documented
Condition100%2/2
$_[1] // 1
MC/DC100%1/1
$_[1] // 1
$_[1]
Truth table100%2/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | sub allow_unknown { $_[0]->_set_allow_unknown($_[1] // 1); $_[0] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
allow_unknown: not called CC=2 SCAR=17.9
Pod
documented
Condition0%0/2
$_[1] // 1
MC/DC0%0/1
$_[1] // 1
$_[1]
Truth table0%0/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | ▶ | sub allow_blessed { $_[0]->_set_allow_blessed($_[1] // 1); $_[0] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
allow_blessed: called CC=2 SCAR=7.2
Pod
documented
Condition50%1/2
$_[1] // 1
MC/DC0%0/1
$_[1] // 1
$_[1]
Truth table50%1/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 2 | ▶ | sub convert_blessed { $_[0]->_set_convert_blessed($_[1] // 1); $_[0] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
convert_blessed: called CC=2 SCAR=7.2
Pod
documented
Condition50%1/2
$_[1] // 1
MC/DC0%0/1
$_[1] // 1
$_[1]
Truth table50%1/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 4 | ▶ | sub max_depth { $_[0]->_checked_max_depth($_[1]); $_[0] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
max_depth: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 3 | ▶ | sub bool { $_[0]->_checked_bool($_[1] // 1); $_[0] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bool: called CC=2 SCAR=6.9
Pod
documented
Condition100%2/2
$_[1] // 1
MC/DC100%1/1
$_[1] // 1
$_[1]
Truth table100%2/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 29 | *boolean = \&bool; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 29 | *boolean_object = \&bool; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # wrap XS new to accept keyword args | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 29 | my $orig_new = JSON::YY->can('new'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 29 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 82 | ▶ | *new = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 82 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 82 | my $self = $orig_new->($class); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 82 | for my $k (keys %args) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 89 | ▶ | my $setter = $SETTERS{$k} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | or Carp::croak("unknown option: $k"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 89 | $self->$setter($args{$k}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 73 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 29 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # Doc overloading: stringify to JSON, boolean always true, eq/ne deep compare | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | package JSON::YY::Doc; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 29 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | # _doc_eq only understands Docs, so compare the JSON text when the other side | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # is not one -- otherwise $doc eq '{"a":1}' is false while "$doc" eq it is true. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 17 | ▶ | sub _eq { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_eq: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 17 | my ($self, $other) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 17 | ▶ | return JSON::YY::_doc_eq($self, $other) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($other) and $other->isa("JSON::YY::Doc")
MC/DC50%1/2
builtin::blessed($other) and $other->isa("JSON::YY::Doc")
builtin::blessed($other)
$other->isa("JSON::YY::Doc")
Truth table66%2/3
A and B
A= builtin::blessed($other)B= $other->isa("JSON::YY::Doc")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | if Scalar::Util::blessed($other) && $other->isa('JSON::YY::Doc'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | # _doc_stringify returns UTF-8 bytes. The UTF8 flag cannot tell a character | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # string from a byte string (chars < 256 may be stored either way), so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | # accept the operand under either reading. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 12 | ▶ | my $str = defined $other ? "$other" : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 12 | my $json = JSON::YY::_doc_stringify($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 12 | ▶ | return 1 if $json eq $str; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 7 | my $enc = $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 7 | utf8::encode($enc); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 7 | return $json eq $enc; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | use overload | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 41 | ▶ | '""' => sub { JSON::YY::_doc_stringify($_[0]) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 2 | ▶ | 'bool' => sub { 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | # without this `fallback` numifies via the string and every pair of Docs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | # compares equal; identity is the only sensible number for a handle | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 6 | ▶ | '0+' => sub { Scalar::Util::refaddr($_[0]) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 'eq' => \&_eq, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 6 | ▶ | 'ne' => sub { !_eq(@_) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 29 | fallback => 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | package JSON::YY; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 29 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||