| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 30 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 30 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 30 | ▶ | package WWW::Shopify::Liquid::Filter::JSON; use base 'WWW::Shopify::Liquid::Filter'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 30 | ▶ | use JSON qw(encode_json decode_json from_json); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 30 | ▶ | use Scalar::Util qw(blessed isweak); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 30 | ▶ | use Clone qw(clone); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | sub walk_data { | ||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
walk_data: not called CC=12 SCAR=50.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 0 | ▶ | if (ref($self) && ref($self) eq "ARRAY" && !isweak($self)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/6
ref $self and ref $self eq "ARRAY" and not builtin::is_weak($self)
ref $self and ref $self eq "ARRAY"
MC/DC0%0/3
ref $self and ref $self eq "ARRAY" and not builtin::is_weak($self)
ref $self
ref $self eq "ARRAY"
not builtin::is_weak($self)
Truth table0%0/4
A and B and not(C)
A= ref $selfB= ref $self eq "ARRAY"C= not builtin::is_weak($self)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 0 | $self->[$_] = walk_data($self->[$_]) for (0..int(@$self)-1); | |||||||||||||||||||||||||||||||||||||||||||||
| 14 | ▶ | } elsif (ref($self) && ref($self) eq "HASH" && !isweak($self)) { | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
ref $self and ref $self eq "HASH" and not builtin::is_weak($self)
ref $self and ref $self eq "HASH"
MC/DC0%0/3
ref $self and ref $self eq "HASH" and not builtin::is_weak($self)
ref $self
ref $self eq "HASH"
not builtin::is_weak($self)
Truth table0%0/4
A and B and not(C)
A= ref $selfB= ref $self eq "HASH"C= not builtin::is_weak($self)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | $self->{$_} = walk_data($self->{$_}) for (keys(%$self)); | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | ▶ | return defined $self && blessed($self) && $self->isa('DateTime') ? $self->iso8601 : $self; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $self and builtin::blessed($self) and $self->isa("DateTime")
defined $self and builtin::blessed($self)
MC/DC0%0/3
defined $self and builtin::blessed($self) and $self->isa("DateTime")
defined $self
builtin::blessed($self)
$self->isa("DateTime")
Truth table0%0/4
A and B and C
A= defined $selfB= builtin::blessed($self)C= $self->isa("DateTime")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | sub operate { | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # We allow decoding with this filter as well. | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | if (!ref($_[2]) && length($_[2]) >= 2) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
operate: not called CC=9 SCAR=45.0
Pod
undocumented
Branch: 1 branch
Condition0%0/3
not ref $_[2] and length $_[2] >= 2
MC/DC0%0/2
not ref $_[2] and length $_[2] >= 2
not ref $_[2]
length $_[2] >= 2
Truth table0%0/3
not(A) and B
A= not ref $_[2]B= length $_[2] >= 2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | my $object = eval { from_json($_[2]) }; | |||||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | return $object if !$@; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | my $object = $_[2] ? (blessed($_[2]) && $_[2]->isa('WWW::Shopify::Model::Item') ? WWW::Shopify::Liquid->liquify_item($_[2]) : walk_data(clone($_[2]))) : $_[2]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
builtin::blessed($_[2]) and $_[2]->isa("WWW::Shopify::Model::Item")
MC/DC0%0/2
builtin::blessed($_[2]) and $_[2]->isa("WWW::Shopify::Model::Item")
builtin::blessed($_[2])
$_[2]->isa("WWW::Shopify::Model::Item")
Truth table0%0/3
A and B
A= builtin::blessed($_[2])B= $_[2]->isa("WWW::Shopify::Model::Item")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | return defined $object && ref($object) ? JSON->new->allow_blessed(1)->encode($object) : '{}'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $object and ref $object
MC/DC0%0/2
defined $object and ref $object
defined $object
ref $object
Truth table0%0/3
A and B
A= defined $objectB= ref $object
| |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 30 | 1; | |||||||||||||||||||||||||||||||||||||||||||||