| 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 | |||||||||||||||||||||||||||||||||
| 5 | { | ||||||||||||||||||||||||||||||||
| 6 | package JSON::Tiny::Subclassable; | ||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 4 | our $AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||||||||||
| 9 | 4 | our $VERSION = '0.005'; | |||||||||||||||||||||||||||||||
| 10 | 4 | our @ISA = qw(JSON::Tiny); | |||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use B; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use Encode (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | BEGIN { | ||||||||||||||||||||||||||||||||
| 17 | 4 | ▶ | eval { require Sub::Name; Sub::Name->import('subname'); 1 } | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=8.4
Subroutine
subname: called CC=1 SCAR=0.8
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 18 | or eval q{ sub subname { $_[1] } }; | ||||||||||||||||||||||||||||||||
| 19 | }; | ||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | sub new { | ||||||||||||||||||||||||||||||||
| 22 | 5 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.7
Pod
documented
| |||||||||||||||||||||||||||||||||
| 23 | 5 | ▶ | bless @_ ? @_ > 1 ? {@_} : {%{$_[0]}} : {}, $class; | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | sub error { | ||||||||||||||||||||||||||||||||
| 27 | 5 | ▶ | $_[0]->{error} = $_[1] if @_ > 1; | ||||||||||||||||||||||||||||||
|
Subroutine
error: called CC=2 SCAR=7.2
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 28 | 5 | return $_[0]->{error}; | |||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | sub pretty { | ||||||||||||||||||||||||||||||||
| 32 | 3 | ▶ | $_[0]->{pretty} = $_[1] if @_ > 1; | ||||||||||||||||||||||||||||||
|
Subroutine
pretty: called CC=2 SCAR=7.2
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 33 | 3 | return $_[0]->{pretty}; | |||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||
| 36 | sub import { | ||||||||||||||||||||||||||||||||
| 37 | 14 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||
| 38 | 14 | my $caller = caller; | |||||||||||||||||||||||||||||||
| 39 | 14 | my $opts = {}; | |||||||||||||||||||||||||||||||
| 40 | 14 | ▶ | while (@_) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 41 | 11 | my $arg = shift; | |||||||||||||||||||||||||||||||
| 42 | 11 | ▶ | $opts->{$arg} = ref $_[0] ? shift @_ : undef; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||
| 44 | 14 | ▶ | if (exists $opts->{'j'}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 45 | 11 | ▶ | my $func = ((ref $opts->{j} eq 'HASH') && $opts->{j}{-as}) || 'j'; | ||||||||||||||||||||||||||||||
|
Condition80%4/5
ref $opts->{'j'} eq 'HASH' && $opts->{'j'}{'-as'} || 'j'
ref $opts->{"j"} eq "HASH" and $opts->{"j"}{"-as"}
MC/DC50%1/2
ref $opts->{'j'} eq 'HASH' && $opts->{'j'}{'-as'} || 'j'
ref $opts->{"j"} eq "HASH"
$opts->{"j"}{"-as"}
Truth table66%2/3
A and B
A= ref $opts->{"j"} eq "HASH"B= $opts->{"j"}{"-as"}
| |||||||||||||||||||||||||||||||||
| 46 | 4 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 47 | 11 | *{"$caller\::$func"} = subname "$class\::j" => sub { | |||||||||||||||||||||||||||||||
| 48 | 3 | ▶ | my $d = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.5
| |||||||||||||||||||||||||||||||||
| 49 | 3 | ▶ | return $class->new->encode($d) if ref $d eq 'ARRAY' || ref $d eq 'HASH'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $d eq "ARRAY" or ref $d eq "HASH"
MC/DC0%0/2
ref $d eq "ARRAY" or ref $d eq "HASH"
ref $d eq "ARRAY"
ref $d eq "HASH"
Truth table33%1/3
A or B
A= ref $d eq "ARRAY"B= ref $d eq "HASH"
| |||||||||||||||||||||||||||||||||
| 50 | 3 | return $class->new->decode($d); | |||||||||||||||||||||||||||||||
| 51 | 11 | }; | |||||||||||||||||||||||||||||||
| 52 | 11 | delete $opts->{'j'}; | |||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | 4 | __PACKAGE__->import('j'); | |||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||
| 58 | # Literal names | ||||||||||||||||||||||||||||||||
| 59 | 4 | my $FALSE = bless \(my $false = 0), 'JSON::Tiny::_Bool'; | |||||||||||||||||||||||||||||||
| 60 | 4 | my $TRUE = bless \(my $true = 1), 'JSON::Tiny::_Bool'; | |||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | # Escaped special character map (with u2028 and u2029) | ||||||||||||||||||||||||||||||||
| 63 | 4 | my %ESCAPE = ( | |||||||||||||||||||||||||||||||
| 64 | '"' => '"', | ||||||||||||||||||||||||||||||||
| 65 | '\\' => '\\', | ||||||||||||||||||||||||||||||||
| 66 | '/' => '/', | ||||||||||||||||||||||||||||||||
| 67 | 'b' => "\x07", | ||||||||||||||||||||||||||||||||
| 68 | 'f' => "\x0C", | ||||||||||||||||||||||||||||||||
| 69 | 'n' => "\x0A", | ||||||||||||||||||||||||||||||||
| 70 | 'r' => "\x0D", | ||||||||||||||||||||||||||||||||
| 71 | 't' => "\x09", | ||||||||||||||||||||||||||||||||
| 72 | 'u2028' => "\x{2028}", | ||||||||||||||||||||||||||||||||
| 73 | 'u2029' => "\x{2029}" | ||||||||||||||||||||||||||||||||
| 74 | ); | ||||||||||||||||||||||||||||||||
| 75 | 4 | my %REVERSE = map { $ESCAPE{$_} => "\\$_" } keys %ESCAPE; | |||||||||||||||||||||||||||||||
| 76 | 4 | for (0x00 .. 0x1F, 0x7F) { | |||||||||||||||||||||||||||||||
| 77 | 132 | my $k = pack 'C', $_; | |||||||||||||||||||||||||||||||
| 78 | 132 | ▶ | $REVERSE{$k} = sprintf '\u%.4X', $_ unless defined $REVERSE{$k}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | # Unicode encoding detection | ||||||||||||||||||||||||||||||||
| 82 | 4 | my $UTF_PATTERNS = { | |||||||||||||||||||||||||||||||
| 83 | 'UTF-32BE' => qr/^\0\0\0[^\0]/, | ||||||||||||||||||||||||||||||||
| 84 | 'UTF-16BE' => qr/^\0[^\0]\0[^\0]/, | ||||||||||||||||||||||||||||||||
| 85 | 'UTF-32LE' => qr/^[^\0]\0\0\0/, | ||||||||||||||||||||||||||||||||
| 86 | 'UTF-16LE' => qr/^[^\0]\0[^\0]\0/ | ||||||||||||||||||||||||||||||||
| 87 | }; | ||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | 4 | my $WHITESPACE_RE = qr/[\x20\x09\x0a\x0d]*/; | |||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | sub DOES { | ||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | my ($proto, $role) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
DOES: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | return 1 if $role eq 'Mojo::JSON'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 94 | 0 | return $proto->SUPER::DOES($role); | |||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | sub decode { | ||||||||||||||||||||||||||||||||
| 98 | 5 | ▶ | my ($self, $bytes) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
decode: called CC=14 SCAR=34.5
Pod
documented
| |||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | # Cleanup | ||||||||||||||||||||||||||||||||
| 101 | 5 | $self->error(undef); | |||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||
| 103 | # Missing input | ||||||||||||||||||||||||||||||||
| 104 | 5 | ▶ | $self->error('Missing or empty input') and return undef unless $bytes; ## no critic (undef) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition20%1/5
$bytes || $self->error('Missing or empty input') && (return undef)
$self->error("Missing or empty input") and return undef
MC/DC0%0/2
$bytes || $self->error('Missing or empty input') && (return undef)
$bytes
$self->error("Missing or empty input")
Truth table33%1/3
A || B
A= $bytesB= $self->error("Missing or empty input")
| |||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | # Remove BOM | ||||||||||||||||||||||||||||||||
| 107 | 5 | $bytes =~ s/^(?:\357\273\277|\377\376\0\0|\0\0\376\377|\376\377|\377\376)//g; | |||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||
| 109 | # Wide characters | ||||||||||||||||||||||||||||||||
| 110 | 5 | ▶ | $self->error('Wide character in input') and return undef ## no critic (undef) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition20%1/5
utf8::downgrade($bytes, 1) || $self->error('Wide character in input') && (return undef)
$self->error("Wide character in input") and return undef
MC/DC0%0/2
utf8::downgrade($bytes, 1) || $self->error('Wide character in input') && (return undef)
utf8::downgrade($bytes, 1)
$self->error("Wide character in input")
Truth table33%1/3
A || B
A= utf8::downgrade($bytes, 1)B= $self->error("Wide character in input")
| |||||||||||||||||||||||||||||||||
| 111 | unless utf8::downgrade($bytes, 1); | ||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||
| 113 | # Detect and decode Unicode | ||||||||||||||||||||||||||||||||
| 114 | 5 | my $encoding = 'UTF-8'; | |||||||||||||||||||||||||||||||
| 115 | 5 | ▶ | $bytes =~ $UTF_PATTERNS->{$_} and $encoding = $_ for keys %$UTF_PATTERNS; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||
| 117 | 5 | my $d_res = eval { $bytes = Encode::decode($encoding, $bytes, 1); 1 }; | |||||||||||||||||||||||||||||||
| 118 | 5 | ▶ | $bytes = undef unless $d_res; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||
| 120 | # Object or array | ||||||||||||||||||||||||||||||||
| 121 | 5 | my $res = eval { | |||||||||||||||||||||||||||||||
| 122 | 5 | local $_ = $bytes; | |||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | # Leading whitespace | ||||||||||||||||||||||||||||||||
| 125 | 5 | m/\G$WHITESPACE_RE/gc; | |||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||
| 127 | # Array | ||||||||||||||||||||||||||||||||
| 128 | 5 | my $ref; | |||||||||||||||||||||||||||||||
| 129 | 5 | ▶ | if (m/\G\[/gc) { $ref = $self->_decode_array() } | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||
| 131 | # Object | ||||||||||||||||||||||||||||||||
| 132 | 5 | elsif (m/\G\{/gc) { $ref = $self->_decode_object() } | |||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||
| 134 | # Unexpected | ||||||||||||||||||||||||||||||||
| 135 | 0 | else { $self->_exception('Expected array or object') } | |||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||
| 137 | # Leftover data | ||||||||||||||||||||||||||||||||
| 138 | 5 | ▶ | unless (m/\G$WHITESPACE_RE\z/gc) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | my $got = ref $ref eq 'ARRAY' ? 'array' : 'object'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 140 | 0 | $self->_exception("Unexpected data after $got"); | |||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||
| 143 | 5 | $ref; | |||||||||||||||||||||||||||||||
| 144 | }; | ||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||
| 146 | # Exception | ||||||||||||||||||||||||||||||||
| 147 | 5 | ▶ | if (!$res && (my $e = $@)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $res and my $e = $@
MC/DC0%0/2
not $res and my $e = $@
not $res
my $e = $@
Truth table33%1/3
not(A) and B
A= not $resB= my $e = $@
| |||||||||||||||||||||||||||||||||
| 148 | 0 | chomp $e; | |||||||||||||||||||||||||||||||
| 149 | 0 | $self->error($e); | |||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||
| 152 | 5 | return $res; | |||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||
| 155 | sub encode { | ||||||||||||||||||||||||||||||||
| 156 | 2 | ▶ | my ($self, $ref) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
encode: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||
| 158 | 2 | my $eof = ''; | |||||||||||||||||||||||||||||||
| 159 | 2 | ▶ | if ($self->pretty) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 160 | 1 | $self->{_indent} = ''; | |||||||||||||||||||||||||||||||
| 161 | 1 | $eof .= "\n"; | |||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||
| 164 | 2 | return Encode::encode 'UTF-8', $self->_encode_values($ref).$eof; | |||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||
| 167 | 1 | ▶ | sub false {$FALSE} | ||||||||||||||||||||||||||||||
|
Subroutine
false: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 168 | 1 | ▶ | sub true {$TRUE} | ||||||||||||||||||||||||||||||
|
Subroutine
true: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||
| 170 | 1 | ▶ | sub _new_hash { +{} } | ||||||||||||||||||||||||||||||
|
Subroutine
_new_hash: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 171 | 3 | ▶ | sub _new_array { +[] } | ||||||||||||||||||||||||||||||
|
Subroutine
_new_array: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||
| 173 | sub _decode_array { | ||||||||||||||||||||||||||||||||
| 174 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_decode_array: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||
| 175 | 3 | my $array = $self->_new_array; | |||||||||||||||||||||||||||||||
| 176 | 3 | ▶ | until (m/\G$WHITESPACE_RE\]/gc) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||
| 178 | # Value | ||||||||||||||||||||||||||||||||
| 179 | 4 | push @$array, $self->_decode_value(); | |||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||
| 181 | # Separator | ||||||||||||||||||||||||||||||||
| 182 | 4 | ▶ | redo if m/\G$WHITESPACE_RE,/gc; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||
| 184 | # End | ||||||||||||||||||||||||||||||||
| 185 | 2 | ▶ | last if m/\G$WHITESPACE_RE\]/gc; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||
| 187 | # Invalid character | ||||||||||||||||||||||||||||||||
| 188 | 0 | $self->_exception('Expected comma or right square bracket while parsing array'); | |||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||
| 191 | 3 | return $array; | |||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||
| 194 | sub _decode_object { | ||||||||||||||||||||||||||||||||
| 195 | 7 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_decode_object: called CC=6 SCAR=18.3
| |||||||||||||||||||||||||||||||||
| 196 | 7 | my $hash = $self->_new_hash; | |||||||||||||||||||||||||||||||
| 197 | 7 | ▶ | until (m/\G$WHITESPACE_RE\}/gc) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||
| 199 | # Quote | ||||||||||||||||||||||||||||||||
| 200 | 20 | ▶ | m/\G$WHITESPACE_RE"/gc | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 201 | or $self->_exception('Expected string while parsing object'); | ||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||
| 203 | # Key | ||||||||||||||||||||||||||||||||
| 204 | 20 | my $key = $self->_decode_string(); | |||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||
| 206 | # Colon | ||||||||||||||||||||||||||||||||
| 207 | 20 | ▶ | m/\G$WHITESPACE_RE:/gc | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 208 | or $self->_exception('Expected colon while parsing object'); | ||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||
| 210 | # Value | ||||||||||||||||||||||||||||||||
| 211 | 20 | $hash->{$key} = $self->_decode_value(); | |||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||
| 213 | # Separator | ||||||||||||||||||||||||||||||||
| 214 | 20 | ▶ | redo if m/\G$WHITESPACE_RE,/gc; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||
| 216 | # End | ||||||||||||||||||||||||||||||||
| 217 | 6 | ▶ | last if m/\G$WHITESPACE_RE\}/gc; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||
| 219 | # Invalid character | ||||||||||||||||||||||||||||||||
| 220 | 0 | $self->_exception('Expected comma or right curly bracket while parsing object'); | |||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||
| 223 | 7 | return $hash; | |||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||
| 226 | sub _decode_string { | ||||||||||||||||||||||||||||||||
| 227 | 20 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_decode_string: called CC=9 SCAR=37.2
| |||||||||||||||||||||||||||||||||
| 228 | 20 | my $pos = pos; | |||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||
| 230 | # Extract string with escaped characters | ||||||||||||||||||||||||||||||||
| 231 | 20 | m#\G(((?:[^\x00-\x1F\\"]|\\(?:["\\/bfnrt]|u[[:xdigit:]]{4})){0,32766})*)#gc; | |||||||||||||||||||||||||||||||
| 232 | 20 | my $str = $1; | |||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||
| 234 | # Missing quote | ||||||||||||||||||||||||||||||||
| 235 | 20 | ▶ | unless (m/\G"/gc) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | $self->_exception('Unexpected character or invalid escape while parsing string') | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 237 | if m/\G[\x00-\x1F\\]/; | ||||||||||||||||||||||||||||||||
| 238 | 0 | $self->_exception('Unterminated string'); | |||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||
| 241 | # Unescape popular characters | ||||||||||||||||||||||||||||||||
| 242 | 20 | ▶ | if (index($str, '\\u') < 0) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 243 | 20 | $str =~ s!\\(["\\/bfnrt])!$ESCAPE{$1}!gs; | |||||||||||||||||||||||||||||||
| 244 | 20 | return $str; | |||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||
| 247 | # Unescape everything else | ||||||||||||||||||||||||||||||||
| 248 | 0 | my $buffer = ''; | |||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | while ($str =~ m/\G([^\\]*)\\(?:([^u])|u(.{4}))/gc) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 250 | 0 | $buffer .= $1; | |||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||
| 252 | # Popular character | ||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | if ($2) { $buffer .= $ESCAPE{$2} } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||
| 255 | # Escaped | ||||||||||||||||||||||||||||||||
| 256 | else { | ||||||||||||||||||||||||||||||||
| 257 | 0 | my $ord = hex $3; | |||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||
| 259 | # Surrogate pair | ||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | if (($ord & 0xF800) == 0xD800) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||
| 262 | # High surrogate | ||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | ($ord & 0xFC00) == 0xD800 | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 264 | or pos($_) = $pos + pos($str), $self->_exception('Missing high-surrogate'); | ||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||
| 266 | # Low surrogate | ||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | $str =~ m/\G\\u([Dd][C-Fc-f]..)/gc | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 268 | or pos($_) = $pos + pos($str), $self->_exception('Missing low-surrogate'); | ||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||
| 270 | # Pair | ||||||||||||||||||||||||||||||||
| 271 | 0 | $ord = 0x10000 + ($ord - 0xD800) * 0x400 + (hex($1) - 0xDC00); | |||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||
| 274 | # Character | ||||||||||||||||||||||||||||||||
| 275 | 0 | $buffer .= pack 'U', $ord; | |||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||
| 279 | # The rest | ||||||||||||||||||||||||||||||||
| 280 | 0 | return $buffer . substr $str, pos($str), length($str); | |||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||
| 283 | sub _decode_value { | ||||||||||||||||||||||||||||||||
| 284 | 24 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_decode_value: called CC=8 SCAR=20.9
| |||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||
| 286 | # Leading whitespace | ||||||||||||||||||||||||||||||||
| 287 | 24 | m/\G$WHITESPACE_RE/gc; | |||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||
| 289 | # String | ||||||||||||||||||||||||||||||||
| 290 | 24 | ▶ | return $self->_decode_string() if m/\G"/gc; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||
| 292 | # Array | ||||||||||||||||||||||||||||||||
| 293 | 24 | ▶ | return $self->_decode_array() if m/\G\[/gc; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||
| 295 | # Object | ||||||||||||||||||||||||||||||||
| 296 | 21 | ▶ | return $self->_decode_object() if m/\G\{/gc; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||
| 298 | # Number | ||||||||||||||||||||||||||||||||
| 299 | 19 | ▶ | return 0 + $1 | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 300 | if m/\G([-]?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?)/gc; | ||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||
| 302 | # True | ||||||||||||||||||||||||||||||||
| 303 | 3 | ▶ | return $self->true if m/\Gtrue/gc; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||
| 305 | # False | ||||||||||||||||||||||||||||||||
| 306 | 2 | ▶ | return $self->false if m/\Gfalse/gc; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||
| 308 | # Null | ||||||||||||||||||||||||||||||||
| 309 | 1 | ▶ | return undef if m/\Gnull/gc; ## no critic (return) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||
| 311 | # Invalid data | ||||||||||||||||||||||||||||||||
| 312 | 0 | $self->_exception('Expected string, array, object, number, boolean or null'); | |||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||
| 315 | sub _encode_array { | ||||||||||||||||||||||||||||||||
| 316 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_encode_array: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||
| 318 | 3 | ▶ | return "[]" unless @{$_[0]}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||
| 320 | 0 | return '[' . join(',', map { $self->_encode_values($_) } @{shift()}) . ']' | |||||||||||||||||||||||||||||||
| 321 | 2 | ▶ | unless exists $self->{_indent}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||
| 323 | 2 | my $indent = $self->{_indent}; | |||||||||||||||||||||||||||||||
| 324 | return "\[\n$indent\t" | ||||||||||||||||||||||||||||||||
| 325 | . join(",\n$indent\t", map { | ||||||||||||||||||||||||||||||||
| 326 | 4 | local $self->{_indent} = "$indent\t"; $self->_encode_values($_) | |||||||||||||||||||||||||||||||
| 327 | 2 | } @{shift()}) | |||||||||||||||||||||||||||||||
| 328 | . "\n$indent\]"; | ||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||
| 331 | sub _encode_object { | ||||||||||||||||||||||||||||||||
| 332 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_encode_object: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||
| 333 | 0 | my $object = shift; | |||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||
| 335 | 0 | my $indent; | |||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | if (exists $self->{_indent}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 337 | 0 | $indent = $self->{_indent}; | |||||||||||||||||||||||||||||||
| 338 | 0 | $self->{_indent} .= "\t"; | |||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||
| 341 | # Encode pairs | ||||||||||||||||||||||||||||||||
| 342 | 0 | my @pairs; | |||||||||||||||||||||||||||||||
| 343 | 0 | ▶ | my $space = defined $indent ? q( ) : q(); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 344 | 0 | ▶ | while (my ($k, $v) = each %$object) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 345 | 0 | push @pairs, sprintf( | |||||||||||||||||||||||||||||||
| 346 | '%s:%s%s', | ||||||||||||||||||||||||||||||||
| 347 | $self->_encode_string($k), | ||||||||||||||||||||||||||||||||
| 348 | $space, | ||||||||||||||||||||||||||||||||
| 349 | $self->_encode_values($v), | ||||||||||||||||||||||||||||||||
| 350 | ); | ||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||
| 353 | 0 | ▶ | if (defined $indent) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 354 | { | ||||||||||||||||||||||||||||||||
| 355 | 0 | $self->{_indent} =~ s/^.//; | |||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | return "{}" unless @pairs; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 357 | 0 | return "\{\n$indent\t" . join(",\n$indent\t", @pairs) . "\n$indent\}"; | |||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||
| 359 | else | ||||||||||||||||||||||||||||||||
| 360 | { | ||||||||||||||||||||||||||||||||
| 361 | 0 | return '{' . join(',', @pairs) . '}'; | |||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||
| 365 | sub _encode_string { | ||||||||||||||||||||||||||||||||
| 366 | 14 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_encode_string: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 367 | 14 | my $string = shift; | |||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||
| 369 | # Escape string | ||||||||||||||||||||||||||||||||
| 370 | 14 | $string =~ s!([\x00-\x1F\x7F\x{2028}\x{2029}\\"/\b\f\n\r\t])!$REVERSE{$1}!gs; | |||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||
| 372 | # Stringify | ||||||||||||||||||||||||||||||||
| 373 | 14 | return "\"$string\""; | |||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||
| 376 | sub _encode_values { | ||||||||||||||||||||||||||||||||
| 377 | 20 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_encode_values: called CC=12 SCAR=29.6
| |||||||||||||||||||||||||||||||||
| 378 | 20 | my $value = shift; | |||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||
| 380 | # Reference | ||||||||||||||||||||||||||||||||
| 381 | 20 | ▶ | if (my $ref = ref $value) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||
| 383 | # Array | ||||||||||||||||||||||||||||||||
| 384 | 9 | ▶ | return $self->_encode_array($value) if $ref eq 'ARRAY'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||
| 386 | # Object | ||||||||||||||||||||||||||||||||
| 387 | 6 | ▶ | return $self->_encode_object($value) if $ref eq 'HASH'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||
| 389 | # True or false | ||||||||||||||||||||||||||||||||
| 390 | 2 | ▶ | return $$value ? 'true' : 'false' if $ref eq 'SCALAR'; | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 391 | 2 | ▶ | return $value ? 'true' : 'false' if $ref eq 'JSON::Tiny::_Bool'; | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||
| 393 | # Blessed reference with TO_JSON method | ||||||||||||||||||||||||||||||||
| 394 | 0 | ▶ | if (Scalar::Util::blessed $value && (my $sub = $value->can('TO_JSON'))) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($value) and my $sub = $value->can("TO_JSON")
MC/DC0%0/2
builtin::blessed($value) and my $sub = $value->can("TO_JSON")
builtin::blessed($value)
my $sub = $value->can("TO_JSON")
Truth table0%0/3
A and B
A= builtin::blessed($value)B= my $sub = $value->can("TO_JSON")
| |||||||||||||||||||||||||||||||||
| 395 | 0 | return $self->_encode_values($value->$sub); | |||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||
| 399 | # Null | ||||||||||||||||||||||||||||||||
| 400 | 11 | ▶ | return 'null' unless defined $value; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||
| 402 | # Number | ||||||||||||||||||||||||||||||||
| 403 | 10 | ▶ | return 0 + $value | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 404 | if B::svref_2object(\$value)->FLAGS & (B::SVp_IOK | B::SVp_NOK); | ||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||
| 406 | # String | ||||||||||||||||||||||||||||||||
| 407 | 0 | return $self->_encode_string($value); | |||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||
| 410 | sub _exception { | ||||||||||||||||||||||||||||||||
| 411 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_exception: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||
| 413 | # Leading whitespace | ||||||||||||||||||||||||||||||||
| 414 | 0 | m/\G$WHITESPACE_RE/gc; | |||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||
| 416 | # Context | ||||||||||||||||||||||||||||||||
| 417 | 0 | my $context = 'Malformed JSON: ' . shift; | |||||||||||||||||||||||||||||||
| 418 | 0 | ▶ | if (m/\G\z/gc) { $context .= ' before end of data' } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 419 | else { | ||||||||||||||||||||||||||||||||
| 420 | 0 | my @lines = split /\n/, substr($_, 0, pos); | |||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | $context .= ' at line ' . @lines . ', offset ' . length(pop @lines || ''); | ||||||||||||||||||||||||||||||
|
Condition0%0/2
pop @lines || ''
MC/DC0%0/1
pop @lines || ''
pop @lines
Truth table0%0/2
A
A= pop @lines
| |||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||
| 424 | # Throw | ||||||||||||||||||||||||||||||||
| 425 | 0 | die "$context\n"; | |||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||
| 429 | { | ||||||||||||||||||||||||||||||||
| 430 | 4 | package JSON::Tiny::_Bool; | |||||||||||||||||||||||||||||||
| 431 | 4 | ▶ | no warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 432 | use overload | ||||||||||||||||||||||||||||||||
| 433 | 4 | ▶ | '0+' => sub { ${$_[0]} }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 434 | 0 | ▶ | '""' => sub { ${$_[0]} }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 435 | 4 | fallback => 1, | |||||||||||||||||||||||||||||||
| 436 | 4 | ▶ | ; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 437 | sub DOES { | ||||||||||||||||||||||||||||||||
| 438 | 0 | ▶ | my ($proto, $role) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
DOES: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||
| 439 | 0 | ▶ | return 1 if $role eq 'Mojo::JSON::_Bool'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 440 | 0 | ▶ | return 1 if $role =~ /^JSON::(?:PP::|XS::)?Boolean$/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 441 | 0 | return $proto->SUPER::DOES($role); | |||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||
| 445 | 4 | 1; | |||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||
| 447 | __END__ | ||||||||||||||||||||||||||||||||