| 1 | package Template::Liquid::Context; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 26 | our $VERSION = '1.0.23'; | |||||||||||||||||||||||||||||||||||||||||||||
| 3 | 26 | require Template::Liquid::Utility; | |||||||||||||||||||||||||||||||||||||||||||||
| 4 | 26 | require Template::Liquid::Error; | |||||||||||||||||||||||||||||||||||||||||||||
| 5 | 26 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 26 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 26 | ▶ | use Scalar::Util; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 370 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 370 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 11 | return bless {scopes => [$args{assigns}], | ||||||||||||||||||||||||||||||||||||||||||||||
| 12 | template => $args{template}, # Required | ||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 370 | errors => [] | |||||||||||||||||||||||||||||||||||||||||||||
| 14 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 127 | ▶ | sub push { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
push: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 127 | my ($s, $context) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 19 | return | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | raise Template::Liquid::Error {type => 'Stack', | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | template => $s->{template}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | message => 'Cannot push new scope!' | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 127 | ▶ | if scalar @{$s->{'scopes'}} == 100; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 127 | ▶ | return push @{$s->{'scopes'}}, (defined $context ? $context : {}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 127 | ▶ | sub pop { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pop: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 127 | my ($s) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 30 | return | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | raise Template::Liquid::Error {type => 'Stack', | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | template => $s->{template}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | message => 'Cannot pop scope!' | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 127 | ▶ | if scalar @{$s->{'scopes'}} == 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 127 | return pop @{$s->{'scopes'}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 107 | ▶ | sub stack { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stack: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 107 | my ($s, $block) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | 107 | my $old_scope = $s->{scopes}[-1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 42 | 107 | $s->push(); | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | 107 | $s->merge($old_scope); | |||||||||||||||||||||||||||||||||||||||||||||
| 44 | 107 | my $result = $block->($s); | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | 107 | $s->pop; | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | 107 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 107 | ▶ | sub merge { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
merge: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 107 | my ($s, $new) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | 107 | return $s->{'scopes'}->[0] = __merge(reverse $s->{scopes}[-1], $new); | |||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub _merge { # Deeply merges data structures | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_merge: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my ($source, $target) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | my $return = $target; | |||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | for (keys %$source) { | |||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if ('ARRAY' eq ref $target->{$_} && | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/6
"ARRAY" eq ref $target->{$_} and "ARRAY" eq ref $source->{$_} || !ref($source->{$_})
"ARRAY" eq ref $source->{$_} or not ref $source->{$_}
MC/DC0%0/3
"ARRAY" eq ref $target->{$_} and "ARRAY" eq ref $source->{$_} || !ref($source->{$_})
"ARRAY" eq ref $target->{$_}
"ARRAY" eq ref $source->{$_}
not ref $source->{$_}
Truth table0%0/4
A and B or not(C)
A= "ARRAY" eq ref $target->{$_}B= "ARRAY" eq ref $source->{$_}C= not ref $source->{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | ('ARRAY' eq ref $source->{$_} || !ref $source->{$_})) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | @{$return->{$_}} = [@{$target->{$_}}, @{$source->{$_}}]; | |||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | ▶ | elsif ('HASH' eq ref $target->{$_} && | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
"HASH" eq ref $target->{$_} and "HASH" eq ref $source->{$_} || !ref($source->{$_})
"HASH" eq ref $source->{$_} or not ref $source->{$_}
MC/DC0%0/3
"HASH" eq ref $target->{$_} and "HASH" eq ref $source->{$_} || !ref($source->{$_})
"HASH" eq ref $target->{$_}
"HASH" eq ref $source->{$_}
not ref $source->{$_}
Truth table0%0/4
A and B or not(C)
A= "HASH" eq ref $target->{$_}B= "HASH" eq ref $source->{$_}C= not ref $source->{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | ('HASH' eq ref $source->{$_} || !ref $source->{$_})) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $return->{$_} = _merge($source->{$_}, $target->{$_}); | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | else { $return->{$_} = $source->{$_}; } | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | return $return; | |||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 26 | my $merge_precedent; | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 107 | ▶ | sub __merge { # unless right is more interesting, this is a left- | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__merge: called CC=4 SCAR=15.4
| |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 107 | my $return = $_[1]; # precedent merge function | |||||||||||||||||||||||||||||||||||||||||||||
| 74 | $merge_precedent ||= { | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 18 | ▶ | SCALAR => {SCALAR => sub { defined $_[0] ? $_[0] : $_[1] }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | ARRAY => sub { $_[1] }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | HASH => sub { $_[1] }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | ARRAY => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 65 | ▶ | SCALAR => sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 65 | ▶ | [@{$_[0]}, defined $_[1] ? $_[1] : ()]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | ARRAY => sub { [@{$_[0]}] }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | HASH => sub { [@{$_[0]}, values %{$_[1]}] }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 41 | ▶ | HASH => {SCALAR => sub { $_[0] }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | ARRAY => sub { $_[0] }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | HASH => sub { _merge($_[0], $_[1], $_[2]) }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 107 | ▶ | }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$merge_precedent ||= {"SCALAR", {"SCALAR", sub {
defined $_[0] ? $_[0] : $_[1];
}
, "ARRAY", sub {
$_[1];
}
, "HASH", sub {
$_[1];
}
}, "ARRAY", {"SCALAR", sub {
[@{$_[0];}, defined $_[1] ? $_[1] : ()];
}
, "ARRAY", sub {
[@{$_[0];}];
}
, "HASH", sub {
[@{$_[0];}, values %{$_[1];}];
}
}, "HASH", {"SCALAR", sub {
$_[0];
}
, "ARRAY", sub {
$_[0];
}
, "HASH", sub {
_merge($_[0], $_[1], $_[2]);
}
}}
MC/DC100%1/1
$merge_precedent ||= {"SCALAR", {"SCALAR", sub {
defined $_[0] ? $_[0] : $_[1];
}
, "ARRAY", sub {
$_[1];
}
, "HASH", sub {
$_[1];
}
}, "ARRAY", {"SCALAR", sub {
[@{$_[0];}, defined $_[1] ? $_[1] : ()];
}
, "ARRAY", sub {
[@{$_[0];}];
}
, "HASH", sub {
[@{$_[0];}, values %{$_[1];}];
}
}, "HASH", {"SCALAR", sub {
$_[0];
}
, "ARRAY", sub {
$_[0];
}
, "HASH", sub {
_merge($_[0], $_[1], $_[2]);
}
}}
$merge_precedent
Truth table100%2/2
A
A= $merge_precedent
| |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 107 | for my $key (keys %{$_[0]}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | my ($left_ref, $right_ref) | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 124 | ▶ | = map { ref($_->{$key}) =~ m[^(HASH|ARRAY)$]o ? $1 : 'SCALAR' } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | ($_[0], $_[1]); | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | #warn sprintf '%-12s [%6s|%-6s]', $key, $left_ref, $right_ref; | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | $return->{$key} = $merge_precedent->{$left_ref}{$right_ref} | ||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 124 | ->($_[0]->{$key}, $_[1]->{$key}); | |||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 107 | return $return; | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 2101 | ▶ | sub get { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=33 SCAR=35.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 2101 | my ($s, $var) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 105 | 2101 | ▶ | return if !defined $var; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 2095 | ▶ | return $2 if $var =~ m[^(["'])(.+)\1$]o; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 1784 | my @path = split $Template::Liquid::Utility::VariableAttributeSeparator, | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | $var; | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 1784 | my $cursor = \$s->{scopes}[-1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | return $var | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 1784 | ▶ | if $var =~ m[^[-\+]?(\d*\.)?\d+$]o && !exists $$cursor->{$path[0]}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$var =~ /^[-\+]?(\d*\.)?\d+$/o and not exists $$$cursor{$path[0]}
MC/DC100%2/2
$var =~ /^[-\+]?(\d*\.)?\d+$/o and not exists $$$cursor{$path[0]}
$var =~ /^[-\+]?(\d*\.)?\d+$/o
not exists $$$cursor{$path[0]}
Truth table100%3/3
A and not(B)
A= $var =~ /^[-\+]?(\d*\.)?\d+$/oB= not exists $$$cursor{$path[0]}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 1053 | ▶ | return if $var eq ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 1041 | ▶ | return '' if $var eq '""'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 1036 | ▶ | return "" if $var eq "''"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 1033 | ▶ | return if $var eq 'null'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 1032 | ▶ | return if $var eq 'nil'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 1031 | ▶ | return if $var eq 'blank'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 1030 | ▶ | return if $var eq 'empty'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 1029 | ▶ | return !1 if $var eq 'false'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 1026 | ▶ | return !!1 if $var eq 'true'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 1022 | ▶ | if ($var =~ m[^\((\S+)\s*\.\.\s*(\S+)\)$]o) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 30 | return [$s->get($1) .. $s->get($2)]; # range | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # print STDERR "DEBUG:var=$var. about to get 1 and 2 from regex"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 127 | # return $s->get($1)->[$2] if $var =~ m'^(.+)\[(\d+)\]$'o; # array index myvar[2] | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 992 | ▶ | if ($var =~ m'^(.+)\[(\d+)\]$'o) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # print STDERR "DEBUG:array index. var=$var. 1=$1,2=$2"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 4 | my $arr = $s->get($1); | |||||||||||||||||||||||||||||||||||||||||||||
| 132 | 4 | ▶ | return $arr->[$2] if $arr; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | return; # return if nothing | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # return $s->get($1)->{$2} if $var =~ m'^(.+)\[(.+)\]$'o; | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 988 | ▶ | if ($var =~ m'^(.+)\[(.+)\]$'o) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # print STDERR "DEBUG:obj property. var=$var. 1=$1,2=$2"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 1 | my $obj = $s->get($1); | |||||||||||||||||||||||||||||||||||||||||||||
| 141 | 1 | ▶ | return $obj->{$2} if $obj; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | return; # return if nothing | |||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 987 | ▶ | STEP: while (@path) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 1178 | my $crumb = shift @path; | |||||||||||||||||||||||||||||||||||||||||||||
| 146 | 1178 | my $reftype = ref $$cursor; | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | 1178 | ▶ | if (Scalar::Util::blessed($$cursor) && $$cursor->can($crumb)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
builtin::blessed($$cursor) and $$cursor->can($crumb)
MC/DC50%1/2
builtin::blessed($$cursor) and $$cursor->can($crumb)
builtin::blessed($$cursor)
$$cursor->can($crumb)
Truth table66%2/3
A and B
A= builtin::blessed($$cursor)B= $$cursor->can($crumb)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 2 | my $can = $$cursor->can($crumb); | |||||||||||||||||||||||||||||||||||||||||||||
| 149 | 2 | my $val = $can->($$cursor); | |||||||||||||||||||||||||||||||||||||||||||||
| 150 | 2 | ▶ | return $val if !scalar @path; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | $cursor = \$val; | |||||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | next STEP; | |||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | elsif ($reftype eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 1150 | ▶ | if (exists $$cursor->{$crumb}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 942 | ▶ | return $$cursor->{$crumb} if !@path; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 185 | $cursor = \$$cursor->{$crumb}; | |||||||||||||||||||||||||||||||||||||||||||||
| 158 | 185 | next STEP; | |||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 208 | return (); | |||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 162 | elsif ($reftype eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 20 | ▶ | return scalar @{$$cursor} if $crumb eq 'size'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 18 | ▶ | $crumb = 0 if $crumb eq 'first'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 18 | ▶ | $crumb = $#$$cursor if $crumb eq 'last'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 18 | ▶ | return () if $crumb =~ m[\D]o; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 17 | ▶ | return () if scalar @$$cursor < $crumb; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 13 | ▶ | return $$cursor->[$crumb] if !scalar @path; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 5 | $cursor = \$$cursor->[$crumb]; | |||||||||||||||||||||||||||||||||||||||||||||
| 170 | 5 | next STEP; | |||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 6 | return (); | |||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 862 | ▶ | sub set { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set: called CC=18 SCAR=31.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 862 | my ($s, $var, $val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 178 | 862 | my $var_reftype = ref $val; | |||||||||||||||||||||||||||||||||||||||||||||
| 179 | 862 | my @path = split $Template::Liquid::Utility::VariableAttributeSeparator, | |||||||||||||||||||||||||||||||||||||||||||||
| 180 | $var; | ||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 862 | my $cursor = \$s->{scopes}[-1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 182 | 862 | ▶ | $cursor = \$$cursor->{shift @path} if (exists $$cursor->{$path[0]}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 862 | ▶ | STEP: while (@path) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 286 | my $crumb = shift @path; | |||||||||||||||||||||||||||||||||||||||||||||
| 185 | 286 | my $reftype = ref $$cursor; | |||||||||||||||||||||||||||||||||||||||||||||
| 186 | 286 | ▶ | if ($reftype eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 280 | ▶ | if (!@path) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 272 | ▶ | if (exists $$cursor->{$crumb}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||
| 190 | # TODO: If the reftype is different, mention it | ||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 272 | return $$cursor->{$crumb} = $val; | |||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 194 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 195 | $$cursor->{$crumb} = $path[0] =~ m[\D] ? {} : [] | ||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 8 | ▶ | if !exists $$cursor->{$crumb}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 8 | $cursor = \$$cursor->{$crumb}; | |||||||||||||||||||||||||||||||||||||||||||||
| 198 | 8 | next STEP; | |||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 201 | elsif ($reftype eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 4 | ▶ | if ($crumb =~ m[\D]) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # TODO: Let the user know | ||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 4 | ▶ | if (!@path) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 1 | ▶ | if (exists $$cursor->[$crumb]) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||
| 209 | # TODO: If the reftype is different, mention it | ||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 1 | return $$cursor->[$crumb] = $val; | |||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 213 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 3 | ▶ | $$cursor->[$crumb] = $path[0] =~ m[\D] ? {} : [] | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 215 | if !exists $$cursor->[$crumb]; | ||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 3 | $cursor = \$$cursor->[$crumb]; | |||||||||||||||||||||||||||||||||||||||||||||
| 217 | 3 | next STEP; | |||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 220 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 2 | ▶ | if (!@path) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 2 | ▶ | if ($crumb =~ m[\D]) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 2 | $$cursor = {}; | |||||||||||||||||||||||||||||||||||||||||||||
| 224 | 2 | return $$cursor->{$crumb} = $val; | |||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | $$cursor = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | return $$cursor->[$crumb] = $val; | |||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 229 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | $$cursor->{$crumb} = $path[0] =~ m[\D] ? {} : [] | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 231 | if !exists $$cursor->[$crumb]; | ||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | $cursor = \$$cursor->{$crumb}; | |||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | next STEP; | |||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 587 | return $$cursor = $val; | |||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 26 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||
| 241 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||
| 243 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||
| 245 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||
| 247 | Template::Liquid::Context - Complex Variable Keeper | ||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||
| 249 | =head1 Description | ||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||
| 251 | This is really only to be used internally. | ||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||
| 253 | =head1 Author | ||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||
| 255 | Sanko Robinson <sanko@cpan.org> - http://sankorobinson.com/ | ||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||
| 257 | CPAN ID: SANKO | ||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||
| 259 | =head1 License and Legal | ||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||
| 261 | Copyright (C) 2009-2022 by Sanko Robinson E<lt>sanko@cpan.orgE<gt> | ||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||
| 263 | This program is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||||||
| 264 | the terms of L<The Artistic License | ||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 2.0|http://www.perlfoundation.org/artistic_license_2_0>. See the F<LICENSE> | ||||||||||||||||||||||||||||||||||||||||||||||
| 266 | file included with this distribution or L<notes on the Artistic License | ||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 2.0|http://www.perlfoundation.org/artistic_2_0_notes> for clarification. | ||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | When separated from the distribution, all original POD documentation is covered | ||||||||||||||||||||||||||||||||||||||||||||||
| 270 | by the L<Creative Commons Attribution-Share Alike 3.0 | ||||||||||||||||||||||||||||||||||||||||||||||
| 271 | License|http://creativecommons.org/licenses/by-sa/3.0/us/legalcode>. See the | ||||||||||||||||||||||||||||||||||||||||||||||
| 272 | L<clarification of the | ||||||||||||||||||||||||||||||||||||||||||||||
| 273 | CCA-SA3.0|http://creativecommons.org/licenses/by-sa/3.0/us/>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||
| 275 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||