JSON/MultiValueOrdered.pm

filter: Statementstmt 95.4% 42 / 44 Branchbran 78.5% 11 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 87.3% 62 / 71 CC 9 SCAR 17.6
CC
9
Cov
89%
_encode_object
9.5
BEGIN
1.0
BEGIN
1.0
CRAP 5.8
« JSON/Tiny/Subclassable.pm ↑ Summary Tie/Hash/MultiValueOrdered.pm »
1 4 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use if $] < 5.010, 'UNIVERSAL::DOES';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 {
7 4 package JSON::MultiValueOrdered;
8
9 4 our $AUTHORITY = 'cpan:TOBYINK';
10 4 our $VERSION = '0.006';
11
12 4 ▶ use base qw(JSON::Tiny::Subclassable);
Subroutine BEGIN: called CC=1 SCAR=0.0
13
14 4 ▶ use Tie::Hash::MultiValueOrdered ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15
16 6 ▶ sub _new_hash { tie my %h, 'Tie::Hash::MultiValueOrdered'; return \%h }
Subroutine _new_hash: called CC=1 SCAR=0.0
17
18 4 ▶ sub _encode_object {
Subroutine _encode_object: called CC=9 SCAR=22.6
19 4 my $self = shift;
20 4 my $object = shift;
21
22 4 my $indent;
23 4 ▶ if (exists $self->{_indent}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"_indent"}) 3 1 4
24 3 $indent = $self->{_indent};
25 3 $self->{_indent} .= "\t";
26 }
27
28 4 my @pairs;
29 4 ▶ my $space = defined $indent ? q( ) : q();
Branch: 1 branch
BranchTrueFalseTotal
defined $indent ? : 3 1 4
30 4 my $tied = tied(%$object);
31 4 ▶ if ($tied and $tied->DOES('Tie::Hash::MultiValueOrdered')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tied and $tied->DOES('Tie::Hash::MultiValueOrdered')) { } 4 0 4
Condition33%1/3
$tied and $tied->DOES("Tie::Hash::MultiValueOrdered")
!ll&&!rl&&r
004
MC/DC0%0/2
$tied and $tied->DOES("Tie::Hash::MultiValueOrdered")
$tied $tied->DOES("Tie::Hash::MultiValueOrdered")
Truth table33%1/3
A and B
A= $tiedB= $tied->DOES("Tie::Hash::MultiValueOrdered")
ABresult
0X0
100
111
32 4 my @list = $tied->pairs;
33 4 ▶ for (my $i = 0; $i < @list; $i+=2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @list) 14 4 18
34 14 push @pairs, sprintf(
35 '%s:%s%s',
36 $self->_encode_string($list[$i]),
37 $space,
38 $self->_encode_values($list[$i + 1]),
39 );
40 }
41 }
42 else {
43 0 ▶ while (my ($k, $v) = each %$object) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$object) 0 0 0
44 0 push @pairs, sprintf(
45 '%s:%s%s',
46 $self->_encode_string($k),
47 $space,
48 $self->_encode_values($v),
49 );
50 }
51 }
52
53 4 ▶ if (defined $indent)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $indent) { } 3 1 4
54 {
55 3 $self->{_indent} =~ s/^.//;
56 3 ▶ return "{}" unless @pairs;
Branch: 1 branch
BranchTrueFalseTotal
unless @pairs 1 2 3
57 2 return "\{\n$indent\t" . join(",\n$indent\t", @pairs) . "\n$indent\}";
58 }
59 else
60 {
61 1 return '{' . join(',', @pairs) . '}';
62 }
63 }
64
65 4 __PACKAGE__->import('j');
66 }
67  
68 4 1;
69  
70 __END__
« JSON/Tiny/Subclassable.pm ↑ Summary Tie/Hash/MultiValueOrdered.pm »