| 1 | package WJSON; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use JSON; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Encode; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Tie::IxHash; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | our $VERSION = '0.08'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | has 'json' => ( | ||||||||||||||||||||||||||||
| 12 | is => 'ro', | ||||||||||||||||||||||||||||
| 13 | isa => 'ArrayRef', | ||||||||||||||||||||||||||||
| 14 | 0 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 15 | 0 | [] | |||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | 2 | ); | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | has 'reference' => ( | ||||||||||||||||||||||||||||
| 20 | is => 'ro', | ||||||||||||||||||||||||||||
| 21 | isa => 'HashRef', | ||||||||||||||||||||||||||||
| 22 | 0 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 23 | {} | ||||||||||||||||||||||||||||
| 24 | 0 | } | |||||||||||||||||||||||||||
| 25 | 2 | ); | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 2 | has 'tmp' => ( | |||||||||||||||||||||||||||
| 28 | is => 'rw', | ||||||||||||||||||||||||||||
| 29 | isa => 'Str' | ||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 2 | has 'encoding' => ( | |||||||||||||||||||||||||||
| 33 | is => 'rw', | ||||||||||||||||||||||||||||
| 34 | isa => 'Str', | ||||||||||||||||||||||||||||
| 35 | default => 'utf-8' | ||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 2 | has 'variable' => ( | |||||||||||||||||||||||||||
| 39 | is => 'rw', | ||||||||||||||||||||||||||||
| 40 | isa => 'Str' | ||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 2 | has 'ordering' => ( | |||||||||||||||||||||||||||
| 44 | is => 'rw', | ||||||||||||||||||||||||||||
| 45 | isa => 'Str', | ||||||||||||||||||||||||||||
| 46 | default => 0 | ||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | sub Open { | ||||||||||||||||||||||||||
|
Subroutine
Open: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 50 | 0 | my ($self, $value) = @_; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if ($value) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if($self->tmp){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 0 | my $tmp = $self->tmp; | |||||||||||||||||||||||||||
| 55 | 0 | ▶ | unless (scalar(@{$self->reference->{$self->tmp}})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 0 | my %hash; | |||||||||||||||||||||||||||
| 57 | 0 | ▶ | tie %hash, 'Tie::IxHash' if $self->ordering; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 0 | $self->Object(\%hash); | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | 0 | $tmp .= '/' . $value; | |||||||||||||||||||||||||||
| 61 | 0 | $self->tmp($tmp); | |||||||||||||||||||||||||||
| 62 | }else{ | ||||||||||||||||||||||||||||
| 63 | 0 | $self->tmp('/' . $value); | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | 0 | $self->reference->{$self->tmp} = []; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub Close { | ||||||||||||||||||||||||||
|
Subroutine
Close: not called CC=48 SCAR=77.6
Pod
documented
| |||||||||||||||||||||||||||||
| 70 | 0 | my ($self, $type) = @_; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | my $tmp = $self->tmp; | |||||||||||||||||||||||||||
| 73 | 0 | $tmp =~ m!/([\w]*?)$!s; | |||||||||||||||||||||||||||
| 74 | 0 | my $key = $1; | |||||||||||||||||||||||||||
| 75 | 0 | $tmp =~ s/\/[\w]*?$//; | |||||||||||||||||||||||||||
| 76 | 0 | $self->tmp($tmp); | |||||||||||||||||||||||||||
| 77 | 0 | ▶ | if ($self->tmp) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | my $total = @{$self->reference->{$self->tmp}} || 1; | ||||||||||||||||||||||||||
|
Condition0%0/2
@{$self->reference->{$self->tmp};} || 1
MC/DC0%0/1
@{$self->reference->{$self->tmp};} || 1
@{$self->reference->{$self->tmp};}
Truth table0%0/2
A
A= @{$self->reference->{$self->tmp};}
| |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if (scalar(@{$self->reference->{$tmp.'/'.$key}}) == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 0 | my $result = $self->reference->{$tmp.'/'.$key}[0]; | |||||||||||||||||||||||||||
| 81 | 0 | ▶ | if (ref($self->reference->{$self->tmp}[$total - 1]) eq 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | if ($type == 1) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 83 | 0 | push(@{$self->reference->{$self->tmp}}, {$key => $result}); | |||||||||||||||||||||||||||
| 84 | }elsif($type == 2) { | ||||||||||||||||||||||||||||
| 85 | 0 | $self->reference->{$self->tmp}[$total - 1]{$key} = [$result]; | |||||||||||||||||||||||||||
| 86 | }elsif($type == 3) { | ||||||||||||||||||||||||||||
| 87 | 0 | push(@{$self->reference->{$self->tmp}}, {$key => [$result]}); | |||||||||||||||||||||||||||
| 88 | }else{ | ||||||||||||||||||||||||||||
| 89 | 0 | $self->reference->{$self->tmp}[$total - 1]{$key} = $result; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | }else{ | ||||||||||||||||||||||||||||
| 92 | 0 | my $t = 1; | |||||||||||||||||||||||||||
| 93 | 0 | ▶ | if ($self->reference->{$self->tmp}[$total - 1]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | $t = scalar(@{$self->reference->{$self->tmp}[$total - 1]}) || 1; | ||||||||||||||||||||||||||
|
Condition0%0/2
scalar @{$self->reference->{$self->tmp}[$total - 1];} || 1
MC/DC0%0/1
scalar @{$self->reference->{$self->tmp}[$total - 1];} || 1
scalar @{$self->reference->{$self->tmp}[$total - 1];}
Truth table0%0/2
A
A= scalar @{$self->reference->{$self->tmp}[$total - 1];}
| |||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | 0 | ▶ | if ($type == 1) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 97 | 0 | push(@{$self->reference->{$self->tmp}[$total - 1]}, {$key => $result}); | |||||||||||||||||||||||||||
| 98 | }elsif($type == 2) { | ||||||||||||||||||||||||||||
| 99 | 0 | $self->reference->{$self->tmp}[$total - 1][$t - 1]{$key} = [$result]; | |||||||||||||||||||||||||||
| 100 | }elsif($type == 3) { | ||||||||||||||||||||||||||||
| 101 | 0 | push(@{$self->reference->{$self->tmp}[$total - 1]}, {$key => [$result]}); | |||||||||||||||||||||||||||
| 102 | }else{ | ||||||||||||||||||||||||||||
| 103 | 0 | ▶ | if ($self->reference->{$self->tmp}[$total - 1][$t - 1]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 0 | $self->reference->{$self->tmp}[$total - 1][$t]{$key} = $result; | |||||||||||||||||||||||||||
| 105 | }else{ | ||||||||||||||||||||||||||||
| 106 | 0 | $self->reference->{$self->tmp}[$total - 1][$t - 1]{$key} = $result; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | }else{ | ||||||||||||||||||||||||||||
| 111 | 0 | my $result = $self->reference->{$tmp.'/'.$key}; | |||||||||||||||||||||||||||
| 112 | 0 | ▶ | $result = [$result] if scalar(@{$result}) <= 1 && $type =~ /(2|3)/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
scalar @{$result;} <= 1 and $type =~ /(2|3)/
MC/DC0%0/2
scalar @{$result;} <= 1 and $type =~ /(2|3)/
scalar @{$result;} <= 1
$type =~ /(2|3)/
Truth table0%0/3
A and B
A= scalar @{$result;} <= 1B= $type =~ /(2|3)/
| |||||||||||||||||||||||||||||
| 113 | 0 | ▶ | if (ref($self->reference->{$self->tmp}[$total - 1]) eq 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | if ($type == 1) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 115 | 0 | push(@{$self->reference->{$self->tmp}}, {$key => $result}); | |||||||||||||||||||||||||||
| 116 | }elsif($type == 2) { | ||||||||||||||||||||||||||||
| 117 | 0 | $self->reference->{$self->tmp}[$total - 1]{$key} = $result; | |||||||||||||||||||||||||||
| 118 | }elsif($type == 3) { | ||||||||||||||||||||||||||||
| 119 | 0 | push(@{$self->reference->{$self->tmp}}, {$key => $result}); | |||||||||||||||||||||||||||
| 120 | }else{ | ||||||||||||||||||||||||||||
| 121 | 0 | $self->reference->{$self->tmp}[$total - 1]{$key} = $result; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | }else{ | ||||||||||||||||||||||||||||
| 124 | 0 | my $t = 1; | |||||||||||||||||||||||||||
| 125 | 0 | ▶ | if ($self->reference->{$self->tmp}[$total - 1]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 0 | ▶ | $t = scalar(@{$self->reference->{$self->tmp}[$total - 1]}) || 1; | ||||||||||||||||||||||||||
|
Condition0%0/2
scalar @{$self->reference->{$self->tmp}[$total - 1];} || 1
MC/DC0%0/1
scalar @{$self->reference->{$self->tmp}[$total - 1];} || 1
scalar @{$self->reference->{$self->tmp}[$total - 1];}
Truth table0%0/2
A
A= scalar @{$self->reference->{$self->tmp}[$total - 1];}
| |||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | 0 | ▶ | if ($type == 1) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 129 | 0 | push(@{$self->reference->{$self->tmp}[$total - 1]}, {$key => $result}); | |||||||||||||||||||||||||||
| 130 | }elsif($type == 2) { | ||||||||||||||||||||||||||||
| 131 | 0 | $self->reference->{$self->tmp}[$total - 1][$t - 1]{$key} = $result; | |||||||||||||||||||||||||||
| 132 | }elsif($type == 3) { | ||||||||||||||||||||||||||||
| 133 | 0 | push(@{$self->reference->{$self->tmp}[$total - 1]}, {$key => $result}); | |||||||||||||||||||||||||||
| 134 | }else{ | ||||||||||||||||||||||||||||
| 135 | 0 | $self->reference->{$self->tmp}[$total - 1][$t - 1]{$key} = $result; | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | }else{ | ||||||||||||||||||||||||||||
| 140 | 0 | ▶ | my $total = scalar(@{$self->json}) || 1; | ||||||||||||||||||||||||||
|
Condition0%0/2
scalar @{$self->json;} || 1
MC/DC0%0/1
scalar @{$self->json;} || 1
scalar @{$self->json;}
Truth table0%0/2
A
A= scalar @{$self->json;}
| |||||||||||||||||||||||||||||
| 141 | 0 | ▶ | if (scalar(@{$self->reference->{$tmp.'/'.$key}}) == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | 0 | my $result = $self->reference->{$tmp.'/'.$key}[0]; | |||||||||||||||||||||||||||
| 143 | 0 | ▶ | if (ref($self->json->[$total - 1]) eq 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | 0 | ▶ | if ($type == 1) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 145 | 0 | push(@{$self->json}, {$key => $result}); | |||||||||||||||||||||||||||
| 146 | }elsif($type == 2) { | ||||||||||||||||||||||||||||
| 147 | 0 | $self->json->[$total - 1]{$key} = [$result]; | |||||||||||||||||||||||||||
| 148 | }elsif($type == 3) { | ||||||||||||||||||||||||||||
| 149 | 0 | push(@{$self->json}, {$key => [$result]}); | |||||||||||||||||||||||||||
| 150 | }else{ | ||||||||||||||||||||||||||||
| 151 | 0 | $self->json->[$total - 1]{$key} = $result; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | }else{ | ||||||||||||||||||||||||||||
| 154 | 0 | my $t = 1; | |||||||||||||||||||||||||||
| 155 | 0 | ▶ | if ($self->json->[$total - 1]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | 0 | ▶ | $t = scalar(@{$self->json->[$total - 1]}) || 1; | ||||||||||||||||||||||||||
|
Condition0%0/2
scalar @{$self->json->[$total - 1];} || 1
MC/DC0%0/1
scalar @{$self->json->[$total - 1];} || 1
scalar @{$self->json->[$total - 1];}
Truth table0%0/2
A
A= scalar @{$self->json->[$total - 1];}
| |||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | 0 | ▶ | if ($type == 1) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 159 | 0 | push(@{$self->json->[$total - 1]}, {$key => $result}); | |||||||||||||||||||||||||||
| 160 | }elsif($type == 2) { | ||||||||||||||||||||||||||||
| 161 | 0 | $self->json->[$total - 1][$t - 1]{$key} = [$result]; | |||||||||||||||||||||||||||
| 162 | }elsif($type == 3) { | ||||||||||||||||||||||||||||
| 163 | 0 | push(@{$self->json->[$total - 1]}, {$key => [$result]}); | |||||||||||||||||||||||||||
| 164 | }else{ | ||||||||||||||||||||||||||||
| 165 | 0 | $self->json->[$total - 1][$t - 1]{$key} = $result; | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | }else{ | ||||||||||||||||||||||||||||
| 169 | 0 | my $result = $self->reference->{$tmp.'/'.$key}; | |||||||||||||||||||||||||||
| 170 | 0 | ▶ | $result = [$result] if scalar(@{$result}) <= 1 && $type =~ /(2|3)/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
scalar @{$result;} <= 1 and $type =~ /(2|3)/
MC/DC0%0/2
scalar @{$result;} <= 1 and $type =~ /(2|3)/
scalar @{$result;} <= 1
$type =~ /(2|3)/
Truth table0%0/3
A and B
A= scalar @{$result;} <= 1B= $type =~ /(2|3)/
| |||||||||||||||||||||||||||||
| 171 | 0 | ▶ | if (ref($self->json->[$total - 1]) eq 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | 0 | ▶ | if ($type == 1) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 173 | 0 | push(@{$self->json}, {$key => $result}); | |||||||||||||||||||||||||||
| 174 | }elsif($type == 2) { | ||||||||||||||||||||||||||||
| 175 | 0 | $self->json->[$total - 1]{$key} = $result; | |||||||||||||||||||||||||||
| 176 | }elsif($type == 3) { | ||||||||||||||||||||||||||||
| 177 | 0 | ▶ | $result = [$result] if scalar(@{$result}) <= 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | 0 | push(@{$self->json}, {$key => $result}); | |||||||||||||||||||||||||||
| 179 | }else{ | ||||||||||||||||||||||||||||
| 180 | 0 | $self->json->[$total - 1]{$key} = $result; | |||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | }else{ | ||||||||||||||||||||||||||||
| 183 | 0 | my $t = 1; | |||||||||||||||||||||||||||
| 184 | 0 | ▶ | if ($self->json->[$total - 1]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 185 | 0 | ▶ | $t = scalar(@{$self->json->[$total - 1]}) || 1; | ||||||||||||||||||||||||||
|
Condition0%0/2
scalar @{$self->json->[$total - 1];} || 1
MC/DC0%0/1
scalar @{$self->json->[$total - 1];} || 1
scalar @{$self->json->[$total - 1];}
Truth table0%0/2
A
A= scalar @{$self->json->[$total - 1];}
| |||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | 0 | ▶ | if ($type == 1) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 188 | 0 | push(@{$self->json}, {$key => $result}); | |||||||||||||||||||||||||||
| 189 | }elsif($type == 2) { | ||||||||||||||||||||||||||||
| 190 | 0 | $self->json->[$total - 1]{$key} = $result; | |||||||||||||||||||||||||||
| 191 | }elsif($type == 3) { | ||||||||||||||||||||||||||||
| 192 | 0 | push(@{$self->json}, {$key => $result}); | |||||||||||||||||||||||||||
| 193 | }else{ | ||||||||||||||||||||||||||||
| 194 | 0 | $self->json->[$total - 1]{$key} = $result; | |||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | 0 | delete($self->reference->{$tmp.'/'.$key}); | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 0 | ▶ | sub Array { | ||||||||||||||||||||||||||
|
Subroutine
Array: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 203 | 0 | my ($self, @values) = @_; | |||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 0 | ▶ | if ($self->tmp) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 206 | 0 | push(@{$self->reference->{$self->tmp}}, [@values]); | |||||||||||||||||||||||||||
| 207 | }else{ | ||||||||||||||||||||||||||||
| 208 | 0 | push(@{$self->json}, [@values]); | |||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 0 | ▶ | sub Object { | ||||||||||||||||||||||||||
|
Subroutine
Object: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||
| 213 | 0 | my ($self, @values) = @_; | |||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 0 | ▶ | if (ref($values[0]) eq 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 216 | 0 | $self->HashObject(@values); | |||||||||||||||||||||||||||
| 217 | }else{ | ||||||||||||||||||||||||||||
| 218 | 0 | ▶ | if (ref($self->reference->{$self->tmp}[0]) eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 219 | 0 | my %hash; | |||||||||||||||||||||||||||
| 220 | 0 | ▶ | tie %hash, 'Tie::IxHash' if $self->ordering; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 221 | 0 | %hash = \@values; | |||||||||||||||||||||||||||
| 222 | 0 | push(@{$self->reference->{$self->tmp}[0]}, \%hash); | |||||||||||||||||||||||||||
| 223 | }else{ | ||||||||||||||||||||||||||||
| 224 | 0 | ▶ | if ($self->tmp) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | 0 | my %hash; | |||||||||||||||||||||||||||
| 226 | 0 | ▶ | tie %hash, 'Tie::IxHash' if $self->ordering; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 227 | 0 | %hash = @values; | |||||||||||||||||||||||||||
| 228 | 0 | push(@{$self->reference->{$self->tmp}}, \%hash); | |||||||||||||||||||||||||||
| 229 | }else{ | ||||||||||||||||||||||||||||
| 230 | 0 | my %hash; | |||||||||||||||||||||||||||
| 231 | 0 | ▶ | tie %hash, 'Tie::IxHash' if $self->ordering; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 232 | 0 | ▶ | if (ref(\@values) eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 233 | 0 | my $n = 0; | |||||||||||||||||||||||||||
| 234 | 0 | ▶ | $n % 2 == 0 ? $hash{$values[$n]} = $values[$n+1] : undef, $n++ for (@values); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 235 | 0 | push(@{$self->json}, \%hash); | |||||||||||||||||||||||||||
| 236 | }else{ | ||||||||||||||||||||||||||||
| 237 | 0 | %hash = \@values; | |||||||||||||||||||||||||||
| 238 | 0 | push(@{$self->json}, \%hash); | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 0 | ▶ | sub HashObject { | ||||||||||||||||||||||||||
|
Subroutine
HashObject: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 246 | 0 | my ($self, @values) = @_; | |||||||||||||||||||||||||||
| 247 | 0 | ▶ | unless (ref($values[0]) eq 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 248 | 0 | $self->Object(@values); | |||||||||||||||||||||||||||
| 249 | }else{ | ||||||||||||||||||||||||||||
| 250 | 0 | foreach my $row (@values){ | |||||||||||||||||||||||||||
| 251 | 0 | ▶ | if ($self->reference->{$self->tmp}[0]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 252 | 0 | ▶ | if (ref($self->reference->{$self->tmp}[0]) eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 253 | 0 | push(@{$self->reference->{$self->tmp}[0]}, $row); | |||||||||||||||||||||||||||
| 254 | }else{ | ||||||||||||||||||||||||||||
| 255 | 0 | push(@{$self->reference->{$self->tmp}}, $row); | |||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||
| 257 | }else{ | ||||||||||||||||||||||||||||
| 258 | 0 | ▶ | if ($self->tmp) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 259 | 0 | push(@{$self->reference->{$self->tmp}}, $row); | |||||||||||||||||||||||||||
| 260 | }else{ | ||||||||||||||||||||||||||||
| 261 | 0 | push(@{$self->json}, $row); | |||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 0 | ▶ | sub Header { | ||||||||||||||||||||||||||
|
Subroutine
Header: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 269 | 0 | return "application/json"; | |||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | 0 | ▶ | sub HeaderJS { | ||||||||||||||||||||||||||
|
Subroutine
HeaderJS: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 273 | 0 | return "application/javascript"; | |||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | 0 | ▶ | sub HeaderCGI { | ||||||||||||||||||||||||||
|
Subroutine
HeaderCGI: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 277 | 0 | return "Content-type: application/json\n\n"; | |||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | 0 | ▶ | sub HeaderJSCGI { | ||||||||||||||||||||||||||
|
Subroutine
HeaderJSCGI: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 281 | 0 | return "Content-type: application/javascript\n\n"; | |||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | 0 | ▶ | sub Print { | ||||||||||||||||||||||||||
|
Subroutine
Print: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 286 | 0 | my ($self, $type) = @_; | |||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | 0 | my $result = undef; | |||||||||||||||||||||||||||
| 289 | 0 | ▶ | if (scalar(@{$self->json}) <= 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 290 | 0 | ▶ | if (ref($self->json->[0]) eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 291 | 0 | ▶ | if (scalar(@{$self->json->[0]}) <= 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 292 | 0 | $result = ${$self->json}[0][0]; | |||||||||||||||||||||||||||
| 293 | }else{ | ||||||||||||||||||||||||||||
| 294 | 0 | $result = ${$self->json}[0]; | |||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||
| 296 | }else{ | ||||||||||||||||||||||||||||
| 297 | 0 | $result = ${$self->json}[0]; | |||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||
| 299 | }else{ | ||||||||||||||||||||||||||||
| 300 | 0 | $result = $self->json; | |||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | 0 | ▶ | $result = [$result] if $type; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | 0 | ▶ | if ($self->variable) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 306 | 0 | return 'var ' . $self->variable . ' = ' . encode $self->encoding, JSON->new->encode($result) . ';'; | |||||||||||||||||||||||||||
| 307 | }else{ | ||||||||||||||||||||||||||||
| 308 | 0 | ▶ | return $result ? encode $self->encoding, JSON->new->encode($result) : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | 2 | 1; | |||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | __END__ | ||||||||||||||||||||||||||||