| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 30 | 4 | my $tied = tied(%$object); | |||||||||||||||||||||||||||
| 31 | 4 | ▶ | if ($tied and $tied->DOES('Tie::Hash::MultiValueOrdered')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$tied and $tied->DOES("Tie::Hash::MultiValueOrdered")
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")
| |||||||||||||||||||||||||||||
| 32 | 4 | my @list = $tied->pairs; | |||||||||||||||||||||||||||
| 33 | 4 | ▶ | for (my $i = 0; $i < @list; $i+=2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 54 | { | ||||||||||||||||||||||||||||
| 55 | 3 | $self->{_indent} =~ s/^.//; | |||||||||||||||||||||||||||
| 56 | 3 | ▶ | return "{}" unless @pairs; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||