blib/lib/WWW/Shopify/Liquid/Lexer.pm

filter: Statementstmt 19.4% 85 / 437 Branchbran 0.0% 0 / 268 Conditioncond 0.0% 0 / 273 MC/DCmcdc 0.0% 0 / 140 Subroutinesub 37.3% 28 / 75 Podpod 0.0% 0 / 16 totaltotal 9.3% 113 / 1209 CC 231 SCAR 71.2
CC
231
Cov
9%
parse_expression
2970.0
parse_token
2652.0
parse_text
1555.8
CRAP 1239.7
↑ Summary blib/lib/WWW/Shopify/Liquid/Tag/Assign.pm »
1 #!/usr/bin/perl
2  
3 28 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 28 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package WWW::Shopify::Liquid::Token;
7 28 ▶use base 'WWW::Shopify::Liquid::Element';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 0 ▶sub new { return bless { line => $_[1], core => $_[2] }, $_[0]; };
Subroutine new: not called CC=1 SCAR=6.9
9 0 ▶sub stringify { return $_[0]->{core}; }
Subroutine stringify: not called CC=1 SCAR=6.9
10 0 ▶sub tokens { return $_[0]; }
Subroutine tokens: not called CC=1 SCAR=6.9
11  
12 package WWW::Shopify::Liquid::Token::Operator;
13 28 ▶use base 'WWW::Shopify::Liquid::Token';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 package WWW::Shopify::Liquid::Token::Operand;
16 28 ▶use base 'WWW::Shopify::Liquid::Token';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 package WWW::Shopify::Liquid::Token::String;
19 28 ▶use base 'WWW::Shopify::Liquid::Token::Operand';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 0 ▶sub process { my ($self, $hash) = @_; return $self->{core}; }
Subroutine process: not called CC=1 SCAR=6.9
21  
22 package WWW::Shopify::Liquid::Token::Number;
23 28 ▶use base 'WWW::Shopify::Liquid::Token::Operand';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 0 ▶sub process { my ($self, $hash) = @_; return $self->{core}; }
Subroutine process: not called CC=1 SCAR=6.9
25  
26 package WWW::Shopify::Liquid::Token::NULL;
27 28 ▶use base 'WWW::Shopify::Liquid::Token::Operand';
Subroutine BEGIN: called CC=1 SCAR=0.0
28 0 ▶sub process { return undef; }
Subroutine process: not called CC=1 SCAR=6.9
29  
30 package WWW::Shopify::Liquid::Token::Bool;
31 28 ▶use base 'WWW::Shopify::Liquid::Token::Operand';
Subroutine BEGIN: called CC=1 SCAR=0.0
32 0 ▶sub process { my ($self, $hash) = @_; return $self->{core}; }
Subroutine process: not called CC=1 SCAR=6.9
33  
34 package WWW::Shopify::Liquid::Token::FunctionCall;
35 28 ▶use base 'WWW::Shopify::Liquid::Token::Operand';
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 28 ▶use Scalar::Util qw(looks_like_number reftype blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 sub new {
40 0 ▶ my $package = shift;
Subroutine new: not called CC=1 SCAR=6.9
41 0 return bless {
42 line => shift,
43 method => shift,
44 self => shift,
45 arguments => [@_]
46 }, $package;
47 }
48  
49 sub process {
50 0 ▶ my ($self, $hash, $action, $pipeline) = @_;
Subroutine process: not called CC=9 SCAR=45.0
51 0 ▶ if ($action eq "render") {
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq "render") 0 0 0
52 0 ▶ die new WWW::Shopify::Liquid::Exception::Renderer::Forbidden($self->{line}) unless $pipeline->make_method_calls;
Branch: 1 branch
BranchTrueFalseTotal
unless $pipeline->make_method_calls 0 0 0
53
54 0 ▶ my @arguments = map { $self->is_processed($_) ? $_ : $_->render($pipeline, $hash) } @{$self->{arguments}};
Branch: 1 branch
BranchTrueFalseTotal
$self->is_processed($_) ? : 0 0 0
55 0 ▶ my $inner_self = $self->is_processed($self->{self}) ? $self->{self} : $self->{self}->render($pipeline, $hash);
Branch: 1 branch
BranchTrueFalseTotal
$self->is_processed($self->{'self'}) ? : 0 0 0
56 0 ▶ my $method = $self->is_processed($self->{method}) ? $self->{method} : $self->{method}->render($pipeline, $hash);
Branch: 1 branch
BranchTrueFalseTotal
$self->is_processed($self->{'method'}) ? : 0 0 0
57 0 ▶ die new WWW::Shopify::Liquid::Exception::Renderer($self->{line}, "Can't find method $method on $inner_self.") unless $inner_self && blessed($inner_self) && !ref($method);
Branch: 1 branch
BranchTrueFalseTotal
unless $inner_self and builtin::blessed($inner_self) and not ref $method 0 0 0
Condition0%0/6
$inner_self and builtin::blessed($inner_self) and not ref $method
!ll&&!rl&&r
000
$inner_self and builtin::blessed($inner_self)
!ll&&!rl&&r
000
MC/DC0%0/3
$inner_self and builtin::blessed($inner_self) and not ref $method
$inner_self builtin::blessed($inner_self) not ref $method
Truth table0%0/4
A and B and not(C)
A= $inner_selfB= builtin::blessed($inner_self)C= not ref $method
ABCresult
0XX0
10X0
1100
1111
58 0 return $inner_self->$method(@arguments);
59 }
60 0 return $self;
61
62 }
63  
64 package WWW::Shopify::Liquid::Token::Variable;
65 28 ▶use base 'WWW::Shopify::Liquid::Token::Operand';
Subroutine BEGIN: called CC=1 SCAR=0.0
66  
67 28 ▶use Scalar::Util qw(looks_like_number reftype blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
68  
69 0 ▶sub new { my $package = shift; return bless { line => shift, core => [@_] }, $package; };
Subroutine new: not called CC=1 SCAR=6.9
70 sub process {
71 0 ▶ my ($self, $hash, $action, $pipeline) = @_;
Subroutine process: not called CC=24 SCAR=64.0
72 0 my $place = $hash;
73
74 0 my @inner = @{$self->{core}};
75 0 my $unprocessed = 0;
76 0 foreach my $part_idx (0..$#inner) {
77 0 my $part = $inner[$part_idx];
78 0 ▶ if (ref($part) eq 'WWW::Shopify::Liquid::Token::Variable::Processing') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $part eq 'WWW::Shopify::Liquid::Token::Variable::Processing') { } 0 0 0
79 0 $place = $part->$action($pipeline, $hash, $place);
80 }
81 else {
82 0 ▶ my $key = $self->is_processed($part) ? $part : $part->$action($pipeline, $hash);
Branch: 1 branch
BranchTrueFalseTotal
$self->is_processed($part) ? : 0 0 0
83
84 0 ▶ return $self unless defined $key && $key ne '';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key and $key ne "" 0 0 0
Condition0%0/3
defined $key and $key ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $key and $key ne ""
defined $key $key ne ""
Truth table0%0/3
A and B
A= defined $keyB= $key ne ""
ABresult
0X0
100
111
85 0 ▶ $self->{core}->[$part_idx] = $key if $self->is_processed($key) && $action eq "optimize";
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_processed($key) and $action eq "optimize" 0 0 0
Condition0%0/3
$self->is_processed($key) and $action eq "optimize"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->is_processed($key) and $action eq "optimize"
$self->is_processed($key) $action eq "optimize"
Truth table0%0/3
A and B
A= $self->is_processed($key)B= $action eq "optimize"
ABresult
0X0
100
111
86 0 ▶ if (defined $place) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $place) 0 0 0
87 0 ▶ if (blessed($place) && $place->isa('WWW::Shopify::Liquid::Resolver')) {
Branch: 4 branches
BranchTrueFalseTotal
if (builtin::blessed($place) and $place->isa('WWW::Shopify::Liquid::Resolver')) { } 0 0 0
elsif (builtin::reftype($place) and builtin::reftype($place) eq 'HASH' and exists $place->{$key}) { } 0 0 0
elsif (builtin::reftype($place) and builtin::reftype($place) eq 'ARRAY' and &looks_like_number($key) and defined $place->[$key]) { } 0 0 0
elsif ($pipeline->make_method_calls and builtin::blessed($place) and $place->can($key)) { } 0 0 0
Condition0%0/3
builtin::blessed($place) and $place->isa("WWW::Shopify::Liquid::Resolver")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($place) and $place->isa("WWW::Shopify::Liquid::Resolver")
builtin::blessed($place) $place->isa("WWW::Shopify::Liquid::Resolver")
Truth table0%0/3
A and B
A= builtin::blessed($place)B= $place->isa("WWW::Shopify::Liquid::Resolver")
ABresult
0X0
100
111
88 0 $place = $place->resolver->($place, $hash, $key);
89 ▶ } elsif (reftype($place) && reftype($place) eq "HASH" && exists $place->{$key}) {
Condition0%0/6
builtin::reftype($place) and builtin::reftype($place) eq "HASH" and exists $place->{$key}
!ll&&!rl&&r
000
builtin::reftype($place) and builtin::reftype($place) eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/3
builtin::reftype($place) and builtin::reftype($place) eq "HASH" and exists $place->{$key}
builtin::reftype($place) builtin::reftype($place) eq "HASH" exists $place->{$key}
Truth table0%0/4
A and B and C
A= builtin::reftype($place)B= builtin::reftype($place) eq "HASH"C= exists $place->{$key}
ABCresult
0XX0
10X0
1100
1111
90 0 $place = $place->{$key};
91 ▶ } elsif (reftype($place) && reftype($place) eq "ARRAY" && looks_like_number($key) && defined $place->[$key]) {
Condition0%0/9
builtin::reftype($place) and builtin::reftype($place) eq "ARRAY" and &looks_like_number($key) and defined $place->[$key]
!ll&&!rl&&r
000
builtin::reftype($place) and builtin::reftype($place) eq "ARRAY" and &looks_like_number($key)
!ll&&!rl&&r
000
builtin::reftype($place) and builtin::reftype($place) eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/4
builtin::reftype($place) and builtin::reftype($place) eq "ARRAY" and &looks_like_number($key) and defined $place->[$key]
builtin::reftype($place) builtin::reftype($place) eq "ARRAY" &looks_like_number($key) defined $place->[$key]
Truth table0%0/5
A and B and C and D
A= builtin::reftype($place)B= builtin::reftype($place) eq "ARRAY"C= &looks_like_number($key)D= defined $place->[$key]
ABCDresult
0XXX0
10XX0
110X0
11100
11111
92 0 $place = $place->[$key];
93 ▶ } elsif ($pipeline->make_method_calls && blessed($place) && $place->can($key)) {
Condition0%0/6
$pipeline->make_method_calls and builtin::blessed($place) and $place->can($key)
!ll&&!rl&&r
000
$pipeline->make_method_calls and builtin::blessed($place)
!ll&&!rl&&r
000
MC/DC0%0/3
$pipeline->make_method_calls and builtin::blessed($place) and $place->can($key)
$pipeline->make_method_calls builtin::blessed($place) $place->can($key)
Truth table0%0/4
A and B and C
A= $pipeline->make_method_callsB= builtin::blessed($place)C= $place->can($key)
ABCresult
0XX0
10X0
1100
1111
94 0 $place = $place->$key;
95 } else {
96 0 $unprocessed = 1;
97 0 $place = undef;
98 }
99 }
100
101 }
102 }
103 0 ▶ return $self if $unprocessed;
Branch: 1 branch
BranchTrueFalseTotal
if $unprocessed 0 0 0
104 0 ▶ return $place->resolver->($place, $hash) if (blessed($place) && $place->isa('WWW::Shopify::Liquid::Resolver'));
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($place) and $place->isa("WWW::Shopify::Liquid::Resolver") 0 0 0
Condition0%0/3
builtin::blessed($place) and $place->isa("WWW::Shopify::Liquid::Resolver")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($place) and $place->isa("WWW::Shopify::Liquid::Resolver")
builtin::blessed($place) $place->isa("WWW::Shopify::Liquid::Resolver")
Truth table0%0/3
A and B
A= builtin::blessed($place)B= $place->isa("WWW::Shopify::Liquid::Resolver")
ABresult
0X0
100
111
105 0 return $place;
106 }
107 0 ▶sub stringify { return join(".", map { $_->stringify } @{$_[0]->{core}}); }
Subroutine stringify: not called CC=1 SCAR=6.9
108  
109 sub set {
110 0 ▶ my ($self, $pipeline, $hash, $value) = @_;
Subroutine set: not called CC=2 SCAR=17.9
111 0 ▶ my @vars = map { $self->is_processed($_) ? $_ : $_->render($pipeline, $hash) } @{$self->{core}};
Branch: 1 branch
BranchTrueFalseTotal
$self->is_processed($_) ? : 0 0 0
112 0 my ($reference) = $pipeline->variable_reference($hash, \@vars);
113 0 $$reference = $value;
114 0 return 1;
115 }
116  
117  
118 sub get {
119 0 ▶ my ($self, $pipeline, $hash) = @_;
Subroutine get: not called CC=3 SCAR=24.8
120 0 ▶ my @vars = map { $self->is_processed($_) ? $_ : $_->render($pipeline, $hash) } @{$self->{core}};
Branch: 1 branch
BranchTrueFalseTotal
$self->is_processed($_) ? : 0 0 0
121 0 my ($reference) = $pipeline->variable_reference($hash, \@vars, 1);
122 0 ▶ return $reference ? $$reference : undef;
Branch: 1 branch
BranchTrueFalseTotal
$reference ? : 0 0 0
123 }
124  
125 package WWW::Shopify::Liquid::Token::Variable::Processing;
126 28 ▶use base 'WWW::Shopify::Liquid::Token::Operand';
Subroutine BEGIN: called CC=1 SCAR=0.0
127 sub process {
128 0 ▶ my ($self, $hash, $argument, $action, $pipeline) = @_;
Subroutine process: not called CC=3 SCAR=24.8
129 0 ▶ return $self if !$self->is_processed($argument);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_processed($argument) 0 0 0
130 0 my $result = $self->{core}->operate($hash, $argument);
131 0 ▶ return $self if !$self->is_processed($result);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_processed($result) 0 0 0
132 0 return $result;
133 }
134  
135 package WWW::Shopify::Liquid::Token::Variable::Named;
136 28 ▶use base 'WWW::Shopify::Liquid::Token::Operand';
Subroutine BEGIN: called CC=1 SCAR=0.0
137  
138 0 ▶sub new { my $package = shift; return bless { line => shift, name => shift, core => shift }, $package; };
Subroutine new: not called CC=1 SCAR=6.9
139 sub process {
140 0 ▶ my ($self, $hash, $action, $pipeline) = @_;
Subroutine process: not called CC=1 SCAR=6.9
141 0 return { $self->{name} => $self->{core}->$action($pipeline, $hash) };
142 }
143  
144  
145 package WWW::Shopify::Liquid::Token::Grouping;
146 28 ▶use base 'WWW::Shopify::Liquid::Token::Operand';
Subroutine BEGIN: called CC=1 SCAR=0.0
147 0 ▶sub new { my $package = shift; return bless { line => shift, members => [@_] }, $package; };
Subroutine new: not called CC=1 SCAR=6.9
148 0 ▶sub members { return @{$_[0]->{members}}; }
Subroutine members: not called CC=1 SCAR=6.9
149  
150 # Parentheses
151 package WWW::Shopify::Liquid::Token::Grouping::Parenthetical;
152 28 ▶use base 'WWW::Shopify::Liquid::Token::Grouping';
Subroutine BEGIN: called CC=1 SCAR=0.0
153  
154 # Like a grouping, but not really.
155 # Square brackets
156 package WWW::Shopify::Liquid::Token::Array;
157 28 ▶use base 'WWW::Shopify::Liquid::Token::Operand';
Subroutine BEGIN: called CC=1 SCAR=0.0
158  
159 sub new {
160 0 ▶ my ($package, $line, @members) = @_;
Subroutine new: not called CC=6 SCAR=37.4
161 # Check to see whether or not the incoming member array is separated by commas.
162 # Should never begin with a comma, should never end with a comma, should always be
163 # 101010101 in terms of data and separators. If this is not the case, then we
164 # Should throw a lexing exception.
165 die new WWW::Shopify::Liquid::Exception::Lexer::InvalidSeparator($line) unless
166 0 ▶ int(grep { ($_ % 2) == 0 && $members[$_]->isa('WWW::Shopify::Liquid::Token::Separator') } (0..$#members)) == 0 &&
Branch: 1 branch
BranchTrueFalseTotal
$_ % 2 == 0 and $members[$_]->isa("WWW::Shopify::Liquid::Token::Separator") 0 0 0
167 0 ▶ int(grep { ($_ % 2) == 1 && (!$members[$_]->isa('WWW::Shopify::Liquid::Token::Separator') || $members[$_]->{core} ne ",") } (0..$#members)) == 0;
Branch: 2 branches
BranchTrueFalseTotal
unless int grep({$_ % 2 == 0 and $members[$_]->isa("WWW::Shopify::Liquid::Token::Separator");} 0 .. $#members) == 0 and int grep({$_ % 2 == 1 and !$members[$_]->isa("WWW::Shopify::Liquid::Token::Separator") || $members[$_]{"core"} ne ",";} 0 .. $#members) == 0 0 0 0
$_ % 2 == 1 and !$members[$_]->isa("WWW::Shopify::Liquid::Token::Separator") || $members[$_]{"core"} ne "," 0 0 0
Condition0%0/9
int grep({$_ % 2 == 0 and $members[$_]->isa("WWW::Shopify::Liquid::Token::Separator");} 0 .. $#members) == 0 and int grep({$_ % 2 == 1 and !$members[$_]->isa("WWW::Shopify::Liquid::Token::Separator") || $members[$_]{"core"} ne ",";} 0 .. $#members) == 0
!ll&&!rl&&r
000
$_ % 2 == 1 && (!$members[$_]->isa('WWW::Shopify::Liquid::Token::Separator') || $members[$_]{'core'} ne ',')
!ll&&!rl&&r
000
not $members[$_]->isa("WWW::Shopify::Liquid::Token::Separator") or $members[$_]{"core"} ne ","
l!l&&r!l&&!r
000
MC/DC0%0/2
int grep({$_ % 2 == 0 and $members[$_]->isa("WWW::Shopify::Liquid::Token::Separator");} 0 .. $#members) == 0 and int grep({$_ % 2 == 1 and !$members[$_]->isa("WWW::Shopify::Liquid::Token::Separator") || $members[$_]{"core"} ne ",";} 0 .. $#members) == 0
int grep({$_ % 2 == 0 and $members[$_]->isa("WWW::Shopify::Liquid::Token::Separator");} 0 .. $#members) == 0 int grep({$_ % 2 == 1 and !$members[$_]->isa("WWW::Shopify::Liquid::Token::Separator") || $members[$_]{"core"} ne ",";} 0 .. $#members) == 0
MC/DC0%0/3
$_ % 2 == 1 && (!$members[$_]->isa('WWW::Shopify::Liquid::Token::Separator') || $members[$_]{'core'} ne ',')
$_ % 2 == 1 not $members[$_]->isa("WWW::Shopify::Liquid::Token::Separator") $members[$_]{"core"} ne ","
Truth table0%0/3
A and B
A= int grep({$_ % 2 == 0 and $members[$_]->isa("WWW::Shopify::Liquid::Token::Separator");} 0 .. $#members) == 0B= int grep({$_ % 2 == 1 and !$members[$_]->isa("WWW::Shopify::Liquid::Token::Separator") || $members[$_]{"core"} ne ",";} 0 .. $#members) == 0
ABresult
0X0
100
111
Truth table0%0/4
A && not(B) or C
A= $_ % 2 == 1B= not $members[$_]->isa("WWW::Shopify::Liquid::Token::Separator")C= $members[$_]{"core"} ne ","
ABCresult
0XX0
1000
11X1
1011
168
169 my $self = bless {
170 line => $line,
171 0 members => [grep { !$_->isa('WWW::Shopify::Liquid::Token::Separator') } @members]
172 }, $package;
173 0 return $self;
174 };
175  
176 0 ▶sub members { return @{$_[0]->{members}}; }
Subroutine members: not called CC=1 SCAR=6.9
177 sub process {
178 0 ▶ my ($self, $hash, $action, $pipeline) = @_;
Subroutine process: not called CC=4 SCAR=30.0
179 0 my @members = $self->members;
180 0 $members[$_] = $members[$_]->$action($pipeline, $hash) for (grep { !$self->is_processed($members[$_]) } (0..$#members));
181 0 ▶ if ($action eq "optimize") {
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq "optimize") 0 0 0
182 0 $self->{members}->[$_] = $_ for (grep { $self->is_processed($members[$_]) } 0..$#members);
183 }
184 0 return [@members];
185 }
186  
187 # Curly brackets
188 package WWW::Shopify::Liquid::Token::Hash;
189 28 ▶use base 'WWW::Shopify::Liquid::Token::Operand';
Subroutine BEGIN: called CC=1 SCAR=0.0
190  
191 0 ▶sub members { return @{$_[0]->{members}}; }
Subroutine members: not called CC=1 SCAR=6.9
192 sub new {
193 0 ▶ my ($package, $line, @members) = @_;
Subroutine new: not called CC=11 SCAR=48.8
194
195 0 @members = map { $_->isa('WWW::Shopify::Liquid::Token::Variable::Named') ? (
196 WWW::Shopify::Liquid::Token::String->new($_->{line}, $_->{name}),
197 WWW::Shopify::Liquid::Token::Separator->new($_->{line}, ':'),
198 $_->{core}
199 0 ▶ ) : $_ } @members;
Branch: 1 branch
BranchTrueFalseTotal
$_->isa('WWW::Shopify::Liquid::Token::Variable::Named') ? : 0 0 0
200
201 die new WWW::Shopify::Liquid::Exception::Lexer::InvalidSeparator($line) unless
202 0 ▶ int(grep { ($_ % 2) == 0 && $members[$_]->isa('WWW::Shopify::Liquid::Token::Separator') } (0..$#members)) == 0 &&
Branch: 1 branch
BranchTrueFalseTotal
$_ % 2 == 0 and $members[$_]->isa("WWW::Shopify::Liquid::Token::Separator") 0 0 0
203 int(grep {
204 ($_ % 4) == 1 && (!$members[$_]->isa('WWW::Shopify::Liquid::Token::Separator') || $members[$_]->{core} ne ":") ||
205 0 ▶ ($_ % 4) == 3 && (!$members[$_]->isa('WWW::Shopify::Liquid::Token::Separator') || $members[$_]->{core} ne ",")
Branch: 1 branch
BranchTrueFalseTotal
$_ % 4 == 1 and !$members[$_]->isa("WWW::Shopify::Liquid::Token::Separator") || $members[$_]{"core"} ne ":" or $_ % 4 == 3 and !$members[$_]->isa("WWW::Shopify::Liquid::Token::Separator") || $members[$_]{"core"} ne "," 0 0 0
Condition0%0/15
$_ % 4 == 1 && (!$members[$_]->isa('WWW::Shopify::Liquid::Token::Separator') || $members[$_]{'core'} ne ':') || $_ % 4 == 3 && (!$members[$_]->isa('WWW::Shopify::Liquid::Token::Separator') || $members[$_]{'core'} ne ',')
l!l&&r!l&&!r
000
$_ % 4 == 1 and !$members[$_]->isa("WWW::Shopify::Liquid::Token::Separator") || $members[$_]{"core"} ne ":"
!ll&&!rl&&r
000
not $members[$_]->isa("WWW::Shopify::Liquid::Token::Separator") or $members[$_]{"core"} ne ":"
l!l&&r!l&&!r
000
$_ % 4 == 3 and !$members[$_]->isa("WWW::Shopify::Liquid::Token::Separator") || $members[$_]{"core"} ne ","
!ll&&!rl&&r
000
not $members[$_]->isa("WWW::Shopify::Liquid::Token::Separator") or $members[$_]{"core"} ne ","
l!l&&r!l&&!r
000
MC/DC0%0/6
$_ % 4 == 1 && (!$members[$_]->isa('WWW::Shopify::Liquid::Token::Separator') || $members[$_]{'core'} ne ':') || $_ % 4 == 3 && (!$members[$_]->isa('WWW::Shopify::Liquid::Token::Separator') || $members[$_]{'core'} ne ',')
$_ % 4 == 1 not $members[$_]->isa("WWW::Shopify::Liquid::Token::Separator") $members[$_]{"core"} ne ":" $_ % 4 == 3 not $members[$_]->isa("WWW::Shopify::Liquid::Token::Separator") $members[$_]{"core"} ne ","
Truth table0%0/10
A and not(B) or C || D and not(E) or F
A= $_ % 4 == 1B= not $members[$_]->isa("WWW::Shopify::Liquid::Token::Separator")C= $members[$_]{"core"} ne ":"D= $_ % 4 == 3E= not $members[$_]->isa("WWW::Shopify::Liquid::Token::Separator")F= $members[$_]{"core"} ne ","
ABCDEFresult
11XXXX1
101XXX1
0XX11X1
0XX1011
10011X1
1001011
0XX0XX0
0XX1000
1000XX0
1001000
206 } (0..$#members)) == 0 &&
207 0 ▶ int(grep { !$_->isa('WWW::Shopify::Liquid::Token::Separator') } @members) % 2 == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless int grep({$_ % 2 == 0 and $members[$_]->isa("WWW::Shopify::Liquid::Token::Separator");} 0 .. $#members) == 0 and int grep({$_ % 4 == 1 and !$members[$_]->isa("WWW::Shopify::Liquid::Token::Separator") || $members[$_]{"core"} ne ":" or $_ % 4 == 3 and !$members[$_]->isa("WWW::Shopify::Liquid::Token::Separator") || $members[$_]{"core"} ne ",";} 0 .. $#members) == 0 and int(grep {not $_->isa("WWW::Shopify::Liquid::Token::Separator");} @members) % 2 == 0 0 0 0
Condition0%0/6
int grep({$_ % 2 == 0 and $members[$_]->isa("WWW::Shopify::Liquid::Token::Separator");} 0 .. $#members) == 0 and int grep({$_ % 4 == 1 and !$members[$_]->isa("WWW::Shopify::Liquid::Token::Separator") || $members[$_]{"core"} ne ":" or $_ % 4 == 3 and !$members[$_]->isa("WWW::Shopify::Liquid::Token::Separator") || $members[$_]{"core"} ne ",";} 0 .. $#members) == 0 and int(grep {not $_->isa("WWW::Shopify::Liquid::Token::Separator");} @members) % 2 == 0
!ll&&!rl&&r
000
int grep({$_ % 2 == 0 and $members[$_]->isa("WWW::Shopify::Liquid::Token::Separator");} 0 .. $#members) == 0 and int grep({$_ % 4 == 1 and !$members[$_]->isa("WWW::Shopify::Liquid::Token::Separator") || $members[$_]{"core"} ne ":" or $_ % 4 == 3 and !$members[$_]->isa("WWW::Shopify::Liquid::Token::Separator") || $members[$_]{"core"} ne ",";} 0 .. $#members) == 0
!ll&&!rl&&r
000
MC/DC0%0/3
int grep({$_ % 2 == 0 and $members[$_]->isa("WWW::Shopify::Liquid::Token::Separator");} 0 .. $#members) == 0 and int grep({$_ % 4 == 1 and !$members[$_]->isa("WWW::Shopify::Liquid::Token::Separator") || $members[$_]{"core"} ne ":" or $_ % 4 == 3 and !$members[$_]->isa("WWW::Shopify::Liquid::Token::Separator") || $members[$_]{"core"} ne ",";} 0 .. $#members) == 0 and int(grep {not $_->isa("WWW::Shopify::Liquid::Token::Separator");} @members) % 2 == 0
int grep({$_ % 2 == 0 and $members[$_]->isa("WWW::Shopify::Liquid::Token::Separator");} 0 .. $#members) == 0 int grep({$_ % 4 == 1 and !$members[$_]->isa("WWW::Shopify::Liquid::Token::Separator") || $members[$_]{"core"} ne ":" or $_ % 4 == 3 and !$members[$_]->isa("WWW::Shopify::Liquid::Token::Separator") || $members[$_]{"core"} ne ",";} 0 .. $#members) == 0 int(grep {not $_->isa("WWW::Shopify::Liquid::Token::Separator");} @members) % 2 == 0
Truth table0%0/4
A and B and C
A= int grep({$_ % 2 == 0 and $members[$_]->isa("WWW::Shopify::Liquid::Token::Separator");} 0 .. $#members) == 0B= int grep({$_ % 4 == 1 and !$members[$_]->isa("WWW::Shopify::Liquid::Token::Separator") || $members[$_]{"core"} ne ":" or $_ % 4 == 3 and !$members[$_]->isa("WWW::Shopify::Liquid::Token::Separator") || $members[$_]{"core"} ne ",";} 0 .. $#members) == 0C= int(grep {not $_->isa("WWW::Shopify::Liquid::Token::Separator");} @members) % 2 == 0
ABCresult
0XX0
10X0
1100
1111
208
209 return bless {
210 line => $line,
211 0 members => [grep { !$_->isa('WWW::Shopify::Liquid::Token::Separator') } @members]
212 }, $package;
213 };
214  
215 sub process {
216 0 ▶ my ($self, $hash, $action, $pipeline) = @_;
Subroutine process: not called CC=4 SCAR=30.0
217 0 my @members = $self->members;
218 0 $members[$_] = $members[$_]->$action($pipeline, $hash) for (grep { !$self->is_processed($members[$_]) } (0..$#members));
219 0 ▶ if ($action eq "optimize") {
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq "optimize") 0 0 0
220 0 $self->{members}->[$_] = $_ for (grep { $self->is_processed($members[$_]) } 0..$#members);
221 }
222 0 return { @members };
223 }
224  
225  
226 package WWW::Shopify::Liquid::Token::Text;
227 28 ▶use base 'WWW::Shopify::Liquid::Token::Operand';
Subroutine BEGIN: called CC=1 SCAR=0.0
228 sub new {
229 0 ▶ my $self = { line => $_[1], core => $_[2] };
Subroutine new: not called CC=3 SCAR=24.8
230 0 my $package = $_[0];
231 0 ▶ $package = 'WWW::Shopify::Liquid::Token::Text::Whitespace' if !defined $_[2] || $_[2] =~ m/^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $_[2] or $_[2] =~ /^\s*$/ 0 0 0
Condition0%0/3
not defined $_[2] or $_[2] =~ /^\s*$/
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $_[2] or $_[2] =~ /^\s*$/
not defined $_[2] $_[2] =~ /^\s*$/
Truth table0%0/3
not(A) or B
A= not defined $_[2]B= $_[2] =~ /^\s*$/
ABresult
1X1
011
000
232 0 return bless $self, $package;
233 };
234 0 ▶sub process { my ($self, $hash) = @_; return $self->{core}; }
Subroutine process: not called CC=1 SCAR=6.9
235  
236 package WWW::Shopify::Liquid::Token::Text::Whitespace;
237 28 ▶use base 'WWW::Shopify::Liquid::Token::Text';
Subroutine BEGIN: called CC=1 SCAR=0.0
238  
239 package WWW::Shopify::Liquid::Token::Tag;
240 28 ▶use base 'WWW::Shopify::Liquid::Token';
Subroutine BEGIN: called CC=1 SCAR=0.0
241 0 ▶sub new { return bless { line => $_[1], tag => $_[2], arguments => $_[3], strip_left => $_[4], strip_right => $_[5] }, $_[0] };
Subroutine new: not called CC=1 SCAR=6.9
242 0 ▶sub tag { return $_[0]->{tag}; }
Subroutine tag: not called CC=1 SCAR=6.9
243 0 ▶sub stringify { return $_[0]->tag; }
Subroutine stringify: not called CC=1 SCAR=6.9
244  
245 package WWW::Shopify::Liquid::Token::Output;
246 28 ▶use base 'WWW::Shopify::Liquid::Token';
Subroutine BEGIN: called CC=1 SCAR=0.0
247 0 ▶sub new { return bless { line => $_[1], core => $_[2], strip_left => $_[3], strip_right => $_[4] }, $_[0]; };
Subroutine new: not called CC=1 SCAR=6.9
248  
249 package WWW::Shopify::Liquid::Token::Separator;
250 28 ▶use base 'WWW::Shopify::Liquid::Token';
Subroutine BEGIN: called CC=1 SCAR=0.0
251  
252  
253 package WWW::Shopify::Liquid::Lexer;
254 28 ▶use base 'WWW::Shopify::Liquid::Pipeline';
Subroutine BEGIN: called CC=1 SCAR=0.0
255 28 ▶use Scalar::Util qw(looks_like_number blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
256  
257 0 ▶sub new { return bless { operators => {}, lexing_halters => {}, transparent_filters => {}, unparse_spaces => 0, parse_escaped_characters => 1 }, $_[0]; }
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
258 0 ▶sub operators { return $_[0]->{operators}; }
Subroutine operators: not called CC=1 SCAR=6.9
Pod undocumented
259 0 ▶sub unparse_spaces { $_[0]->{unparse_spaces} = $_[1] if defined $_[1]; return $_[0]->{unparse_spaces}; }
Subroutine unparse_spaces: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[1] 0 0 0
260 0 ▶sub parse_escaped_characters { $_[0]->{parse_escaped_characters} = $_[1] if defined $_[1]; return $_[0]->{parse_escaped_characters}; }
Subroutine parse_escaped_characters: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[1] 0 0 0
261 0 ▶sub register_operator { $_[0]->{operators}->{$_} = $_[1] for ($_[1]->symbol); }
Subroutine register_operator: not called CC=2 SCAR=17.9
Pod undocumented
262 sub register_tag {
263 0 ▶ my ($self, $package) = @_;
Subroutine register_tag: not called CC=3 SCAR=24.8
Pod undocumented
264 0 ▶ $self->{lexing_halters}->{$package->name} = $package if $package->is_enclosing && $package->inner_halt_lexing;
Branch: 1 branch
BranchTrueFalseTotal
if $package->is_enclosing and $package->inner_halt_lexing 0 0 0
Condition0%0/3
$package->is_enclosing and $package->inner_halt_lexing
!ll&&!rl&&r
000
MC/DC0%0/2
$package->is_enclosing and $package->inner_halt_lexing
$package->is_enclosing $package->inner_halt_lexing
Truth table0%0/3
A and B
A= $package->is_enclosingB= $package->inner_halt_lexing
ABresult
0X0
100
111
265 }
266 sub register_filter {
267 0 ▶ my ($self, $package) = @_;
Subroutine register_filter: not called CC=2 SCAR=17.9
Pod undocumented
268 0 ▶ $self->{transparent_filters}->{$package->name} = $package if ($package->transparent);
Branch: 1 branch
BranchTrueFalseTotal
if $package->transparent 0 0 0
269 }
270 0 ▶sub transparent_filters { return $_[0]->{transparent_filters}; }
Subroutine transparent_filters: not called CC=1 SCAR=6.9
Pod undocumented
271  
272 sub parse_token {
273 0 ▶ my ($self, $line, $token) = @_;
Subroutine parse_token: not called CC=51 SCAR=78.8
Pod undocumented
274
275 # Strip token of whitespace.
276 0 ▶ return undef unless defined $token;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $token 0 0 0
277 0 $token =~ s/^\s*(.*?)\s*$/$1/;
278 0 ▶ return WWW::Shopify::Liquid::Token::Operator->new($line, $token) if $self->operators->{$token};
Branch: 1 branch
BranchTrueFalseTotal
if $self->operators->{$token} 0 0 0
279 0 ▶ return WWW::Shopify::Liquid::Token::String->new($line, do {
Branch: 1 branch
BranchTrueFalseTotal
if $token =~ /^'(.*)'$/s or $token =~ /^"(.*)"$/s 0 0 0
Condition0%0/3
$token =~ /^'(.*)'$/s or $token =~ /^"(.*)"$/s
l!l&&r!l&&!r
000
MC/DC0%0/2
$token =~ /^'(.*)'$/s or $token =~ /^"(.*)"$/s
$token =~ /^'(.*)'$/s $token =~ /^"(.*)"$/s
Truth table0%0/3
A or B
A= $token =~ /^'(.*)'$/sB= $token =~ /^"(.*)"$/s
ABresult
1X1
011
000
280 0 my $string = $1;
281 0 ▶ if ($self->parse_escaped_characters) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->parse_escaped_characters) 0 0 0
282 0 $string =~ s/\\r/\r/g;
283 0 $string =~ s/\\n/\n/g;
284 0 $string =~ s/\\t/\t/g;
285 }
286 0 $string;
287 }) if $token =~ m/^'(.*)'$/s || $token =~ m/^"(.*)"$/s;
288 0 ▶ return WWW::Shopify::Liquid::Token::Number->new($line, $1) if looks_like_number($token);
Branch: 1 branch
BranchTrueFalseTotal
if &looks_like_number($token) 0 0 0
289 0 ▶ return WWW::Shopify::Liquid::Token::NULL->new() if $token eq '' || $token eq 'null';
Branch: 1 branch
BranchTrueFalseTotal
if $token eq "" or $token eq "null" 0 0 0
Condition0%0/3
$token eq "" or $token eq "null"
l!l&&r!l&&!r
000
MC/DC0%0/2
$token eq "" or $token eq "null"
$token eq "" $token eq "null"
Truth table0%0/3
A or B
A= $token eq ""B= $token eq "null"
ABresult
1X1
011
000
290 0 ▶ return WWW::Shopify::Liquid::Token::Separator->new($line, $token) if ($token eq ":" || $token eq "," || $token eq ".");
Branch: 1 branch
BranchTrueFalseTotal
if $token eq ":" or $token eq "," or $token eq "." 0 0 0
Condition0%0/6
$token eq ":" or $token eq "," or $token eq "."
l!l&&r!l&&!r
000
$token eq ":" or $token eq ","
l!l&&r!l&&!r
000
MC/DC0%0/3
$token eq ":" or $token eq "," or $token eq "."
$token eq ":" $token eq "," $token eq "."
Truth table0%0/4
A or B or C
A= $token eq ":"B= $token eq ","C= $token eq "."
ABCresult
1XX1
01X1
0011
0000
291 0 ▶ return WWW::Shopify::Liquid::Token::Array->new($line) if ($token eq "[]");
Branch: 1 branch
BranchTrueFalseTotal
if $token eq "[]" 0 0 0
292 0 ▶ return WWW::Shopify::Liquid::Token::Hash->new($line) if ($token eq "{}");
Branch: 1 branch
BranchTrueFalseTotal
if $token eq "{}" 0 0 0
293 # We're a variable. Let's see what's going on. Split along non quoted . and [ ] fields.
294 0 my ($squot, $dquot, $start, @parts) = (0,0,0);
295 # customer['test']['b']
296 0 my $open_square_bracket = 0;
297 0 my $open_curly_bracket = 0;
298 0 ▶ while ($token =~ m/(\.|\[|\]|\{|\}|(?<!\\)\"|(?<!\\)\'|\b$)/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token =~ /(\.|\[|\]|\{|\}|(?<!\\)\"|(?<!\\)\'|\b$)/g) 0 0 0
299 0 my $sym = $&;
300 0 my $begin = $-[0];
301 0 my $end = $+[0];
302 0 ▶ if (!$squot && !$dquot) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($squot or $dquot) 0 0 0
Condition0%0/3
$squot or $dquot
l!l&&r!l&&!r
000
MC/DC0%0/2
$squot or $dquot
$squot $dquot
Truth table0%0/3
A or B
A= $squotB= $dquot
ABresult
1X1
011
000
303 0 ▶ $open_square_bracket-- if ($sym && $sym eq "]");
Branch: 1 branch
BranchTrueFalseTotal
if $sym and $sym eq "]" 0 0 0
Condition0%0/3
$sym and $sym eq "]"
!ll&&!rl&&r
000
MC/DC0%0/2
$sym and $sym eq "]"
$sym $sym eq "]"
Truth table0%0/3
A and B
A= $symB= $sym eq "]"
ABresult
0X0
100
111
304 0 ▶ $open_curly_bracket-- if ($sym && $sym eq "}");
Branch: 1 branch
BranchTrueFalseTotal
if $sym and $sym eq "}" 0 0 0
Condition0%0/3
$sym and $sym eq "}"
!ll&&!rl&&r
000
MC/DC0%0/2
$sym and $sym eq "}"
$sym $sym eq "}"
Truth table0%0/3
A and B
A= $symB= $sym eq "}"
ABresult
0X0
100
111
305 0 ▶ if (($sym eq "." || $sym eq "]" || $sym eq "[" || $sym eq "{" || $sym eq "}" || !$sym) && $open_square_bracket == 0 && $open_curly_bracket == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sym eq "." || $sym eq "]" || $sym eq "[" || $sym eq "{" || $sym eq "}" || !$sym and $open_square_bracket == 0 and $open_curly_bracket == 0) 0 0 0
Condition0%0/21
$sym eq "." || $sym eq "]" || $sym eq "[" || $sym eq "{" || $sym eq "}" || !$sym and $open_square_bracket == 0 and $open_curly_bracket == 0
!ll&&!rl&&r
000
$sym eq "." || $sym eq "]" || $sym eq "[" || $sym eq "{" || $sym eq "}" || !$sym and $open_square_bracket == 0
!ll&&!rl&&r
000
$sym eq "." or $sym eq "]" or $sym eq "[" or $sym eq "{" or $sym eq "}" or not $sym
l!l&&r!l&&!r
000
$sym eq "." or $sym eq "]" or $sym eq "[" or $sym eq "{" or $sym eq "}"
l!l&&r!l&&!r
000
$sym eq "." or $sym eq "]" or $sym eq "[" or $sym eq "{"
l!l&&r!l&&!r
000
$sym eq "." or $sym eq "]" or $sym eq "["
l!l&&r!l&&!r
000
$sym eq "." or $sym eq "]"
l!l&&r!l&&!r
000
MC/DC0%0/8
$sym eq "." || $sym eq "]" || $sym eq "[" || $sym eq "{" || $sym eq "}" || !$sym and $open_square_bracket == 0 and $open_curly_bracket == 0
$sym eq "." $sym eq "]" $sym eq "[" $sym eq "{" $sym eq "}" not $sym $open_square_bracket == 0 $open_curly_bracket == 0
Truth table0%0/19
A or B or C or D or E or not(F) and G and H
A= $sym eq "."B= $sym eq "]"C= $sym eq "["D= $sym eq "{"E= $sym eq "}"F= not $symG= $open_square_bracket == 0H= $open_curly_bracket == 0
ABCDEFGHresult
000000XX0
1XXXXX0X0
01XXXX0X0
001XXX0X0
0001XX0X0
00001X0X0
0000010X0
1XXXXX100
01XXXX100
001XXX100
0001XX100
00001X100
000001100
1XXXXX111
01XXXX111
001XXX111
0001XX111
00001X111
000001111
306 0 my $contents = substr($token, $start, $begin - $start);
307
308 0 ▶ if (defined $contents && $contents !~ m/^\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $contents and not $contents =~ /^\s*$/) 0 0 0
Condition0%0/3
defined $contents and not $contents =~ /^\s*$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $contents and not $contents =~ /^\s*$/
defined $contents not $contents =~ /^\s*$/
Truth table0%0/3
A and not(B)
A= defined $contentsB= not $contents =~ /^\s*$/
ABresult
0X0
100
111
309 0 my @variables = ();
310 0 ▶ if (!$sym || $sym eq "." || $sym eq "[") {
Branch: 3 branches
BranchTrueFalseTotal
if (not $sym or $sym eq '.' or $sym eq '[') { } 0 0 0
elsif ($sym eq ']') { } 0 0 0
elsif ($sym eq '}') { } 0 0 0
Condition0%0/6
not $sym or $sym eq "." or $sym eq "["
l!l&&r!l&&!r
000
not $sym or $sym eq "."
l!l&&r!l&&!r
000
MC/DC0%0/3
not $sym or $sym eq "." or $sym eq "["
not $sym $sym eq "." $sym eq "["
Truth table0%0/4
not(A) or B or C
A= not $symB= $sym eq "."C= $sym eq "["
ABCresult
1XX1
01X1
0011
0000
311 0 ▶ @variables = $self->transparent_filters->{$contents} ? WWW::Shopify::Liquid::Token::Variable::Processing->new($line, $self->transparent_filters->{$contents}) : WWW::Shopify::Liquid::Token::String->new($line, $contents);
Branch: 1 branch
BranchTrueFalseTotal
$self->transparent_filters->{$contents} ? : 0 0 0
312 }
313 elsif ($sym eq "]") {
314 0 @variables = $self->parse_expression($line, $contents);
315 0 ▶ return WWW::Shopify::Liquid::Token::Array->new($line, @variables) if (int(@parts) == 0);
Branch: 1 branch
BranchTrueFalseTotal
if int @parts == 0 0 0 0
316 }
317 elsif ($sym eq "}") {
318 0 @variables = $self->parse_expression($line, $contents);
319 0 ▶ return WWW::Shopify::Liquid::Token::Hash->new($line, @variables) if (int(@parts) == 0);
Branch: 1 branch
BranchTrueFalseTotal
if int @parts == 0 0 0 0
320 }
321 0 ▶ if (int(@variables) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (int @variables > 0) 0 0 0
322 0 ▶ if (int(@variables) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (int @variables == 1) { } 0 0 0
323 0 push(@parts, @variables);
324 }
325 else {
326 0 push(@parts, WWW::Shopify::Liquid::Token::Grouping->new($line, @variables)) ;
327 }
328 }
329 }
330 }
331 0 ▶ $start = $end if $sym ne '"' && $sym ne "'" && !$open_curly_bracket && !$open_square_bracket;
Branch: 1 branch
BranchTrueFalseTotal
if $sym ne "\"" and $sym ne "'" and not $open_curly_bracket and not $open_square_bracket 0 0 0
Condition0%0/9
$sym ne "\"" and $sym ne "'" and not $open_curly_bracket and not $open_square_bracket
!ll&&!rl&&r
000
$sym ne "\"" and $sym ne "'" and not $open_curly_bracket
!ll&&!rl&&r
000
$sym ne "\"" and $sym ne "'"
!ll&&!rl&&r
000
MC/DC0%0/4
$sym ne "\"" and $sym ne "'" and not $open_curly_bracket and not $open_square_bracket
$sym ne "\"" $sym ne "'" not $open_curly_bracket not $open_square_bracket
Truth table0%0/5
A and B and not(C) and not(D)
A= $sym ne "\""B= $sym ne "'"C= not $open_curly_bracketD= not $open_square_bracket
ABCDresult
0XXX0
10XX0
110X0
11100
11111
332 0 ▶ $open_square_bracket++ if ($sym && $sym eq "[");
Branch: 1 branch
BranchTrueFalseTotal
if $sym and $sym eq "[" 0 0 0
Condition0%0/3
$sym and $sym eq "["
!ll&&!rl&&r
000
MC/DC0%0/2
$sym and $sym eq "["
$sym $sym eq "["
Truth table0%0/3
A and B
A= $symB= $sym eq "["
ABresult
0X0
100
111
333 0 ▶ $open_curly_bracket++ if ($sym && $sym eq "{");
Branch: 1 branch
BranchTrueFalseTotal
if $sym and $sym eq "{" 0 0 0
Condition0%0/3
$sym and $sym eq "{"
!ll&&!rl&&r
000
MC/DC0%0/2
$sym and $sym eq "{"
$sym $sym eq "{"
Truth table0%0/3
A and B
A= $symB= $sym eq "{"
ABresult
0X0
100
111
334
335 }
336 0 ▶ $squot = !$squot if $token eq "'";
Branch: 1 branch
BranchTrueFalseTotal
if $token eq "'" 0 0 0
337 0 ▶ $dquot = !$dquot if $token eq '"';
Branch: 1 branch
BranchTrueFalseTotal
if $token eq "\"" 0 0 0
338 }
339 0 return WWW::Shopify::Liquid::Token::Variable->new($line, @parts);
340 }
341  
342 28 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
343 # Returns a single token repsending the whole a expression.
344 sub parse_expression {
345 0 ▶ my ($self, $line, $exp) = @_;
Subroutine parse_expression: not called CC=54 SCAR=80.0
Pod undocumented
346 0 ▶ return () if !defined $exp || $exp eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $exp or $exp eq "" 0 0 0
Condition0%0/3
not defined $exp or $exp eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $exp or $exp eq ""
not defined $exp $exp eq ""
Truth table0%0/3
not(A) or B
A= not defined $expB= $exp eq ""
ABresult
1X1
011
000
347 0 my @tokens = ();
348 0 my ($start_paren, $start_space, $level, $squot, $dquot, $start_sq, $sq_level, $start_hsh, $hsh_level) = (undef, 0, 0, 0, 0, undef, 0, undef, 0);
349 # We regex along parentheses, quotation marks (both kinds), whitespace, and non-word-operators.
350 # We sort along length, so that we make sure to get all the largest operators first, so that way if a larger operator is made from a smaller one (=, ==)
351 # There's no confusion, we always try to match the largest first.
352 0 my $non_word_operators = join("|", map { quotemeta($_) } grep { $_ =~ m/^\W+$/; } sort { length($b) <=> length($a) } keys(%{$self->operators}));
353 0 ▶ while ($exp =~ m/(?:\(|\)|\]|\[|\}|\{|(?<!\\)["”“]|(?<!\\)['‘’]|(\s+|$)|($non_word_operators|,|:))/sg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exp =~ /(?:\(|\)|\]|\[|\}|\{|(?<!\\)["\x{201d}\x{201c}]|(?<!\\)['\x{2018}\x{2019}]|(\s+|$)|($non_word_operators|,|:))/gs) 0 0 0
354 0 my ($rs, $re, $rc, $whitespace, $nword_op) = ($-[0], $+[0], $&, $1, $2);
355 # Specifically to allow variables to have a - in them, and be treated as a long literal, instead of a minus sign.
356 # This is terrible behaviour, but mimics Shopify's lexer.
357 # Only if of course the entire first half of this ISN'T a number, though. 'cause that'd be insane.
358 0 ▶ next if $nword_op && $nword_op eq "-" && $rs > 0 && substr($exp, $rs-1, 1) ne " " && substr($exp, 0, $rs) !~ m/\b\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
if $nword_op and $nword_op eq "-" and $rs > 0 and substr($exp, $rs - 1, 1) ne " " and not substr($exp, 0, $rs) =~ /\b\d+$/ 0 0 0
Condition0%0/12
$nword_op and $nword_op eq "-" and $rs > 0 and substr($exp, $rs - 1, 1) ne " " and not substr($exp, 0, $rs) =~ /\b\d+$/
!ll&&!rl&&r
000
$nword_op and $nword_op eq "-" and $rs > 0 and substr($exp, $rs - 1, 1) ne " "
!ll&&!rl&&r
000
$nword_op and $nword_op eq "-" and $rs > 0
!ll&&!rl&&r
000
$nword_op and $nword_op eq "-"
!ll&&!rl&&r
000
MC/DC0%0/5
$nword_op and $nword_op eq "-" and $rs > 0 and substr($exp, $rs - 1, 1) ne " " and not substr($exp, 0, $rs) =~ /\b\d+$/
$nword_op $nword_op eq "-" $rs > 0 substr($exp, $rs - 1, 1) ne " " not substr($exp, 0, $rs) =~ /\b\d+$/
Truth table0%0/6
A and B and C and D and not(E)
A= $nword_opB= $nword_op eq "-"C= $rs > 0D= substr($exp, $rs - 1, 1) ne " "E= not substr($exp, 0, $rs) =~ /\b\d+$/
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
359 0 ▶ if (!$squot && !$dquot) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($squot or $dquot) 0 0 0
Condition0%0/3
$squot or $dquot
l!l&&r!l&&!r
000
MC/DC0%0/2
$squot or $dquot
$squot $dquot
Truth table0%0/3
A or B
A= $squotB= $dquot
ABresult
1X1
011
000
360 0 ▶ $start_paren = $re if $rc eq "(" && $level++ == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $rc eq "(" and $level++ == 0 0 0 0
Condition0%0/3
$rc eq "(" and $level++ == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$rc eq "(" and $level++ == 0
$rc eq "(" $level++ == 0
Truth table0%0/3
A and B
A= $rc eq "("B= $level++ == 0
ABresult
0X0
100
111
361 0 ▶ $start_sq = $re if $rc eq "[" && $sq_level++ == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $rc eq "[" and $sq_level++ == 0 0 0 0
Condition0%0/3
$rc eq "[" and $sq_level++ == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$rc eq "[" and $sq_level++ == 0
$rc eq "[" $sq_level++ == 0
Truth table0%0/3
A and B
A= $rc eq "["B= $sq_level++ == 0
ABresult
0X0
100
111
362 0 ▶ $start_hsh = $re if $rc eq "{" && $hsh_level++ == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $rc eq "{" and $hsh_level++ == 0 0 0 0
Condition0%0/3
$rc eq "{" and $hsh_level++ == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$rc eq "{" and $hsh_level++ == 0
$rc eq "{" $hsh_level++ == 0
Truth table0%0/3
A and B
A= $rc eq "{"B= $hsh_level++ == 0
ABresult
0X0
100
111
363 # Deal with parentheses; always the highest level of operation, except when inside a square bracket.
364 0 ▶ if ($rc eq ")" && --$level == 0 && $sq_level == 0 && $hsh_level == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rc eq ")" and --$level == 0 and $sq_level == 0 and $hsh_level == 0) 0 0 0
Condition0%0/9
$rc eq ")" and --$level == 0 and $sq_level == 0 and $hsh_level == 0
!ll&&!rl&&r
000
$rc eq ")" and --$level == 0 and $sq_level == 0
!ll&&!rl&&r
000
$rc eq ")" and --$level == 0
!ll&&!rl&&r
000
MC/DC0%0/4
$rc eq ")" and --$level == 0 and $sq_level == 0 and $hsh_level == 0
$rc eq ")" --$level == 0 $sq_level == 0 $hsh_level == 0
Truth table0%0/5
A and B and C and D
A= $rc eq ")"B= --$level == 0C= $sq_level == 0D= $hsh_level == 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
365 0 $start_space = $re;
366 0 push(@tokens, WWW::Shopify::Liquid::Token::Grouping->new($line, $self->parse_expression($line, substr($exp, $start_paren, $rs - $start_paren))));
367 }
368 0 ▶ --$sq_level if $rc eq "]";
Branch: 1 branch
BranchTrueFalseTotal
if $rc eq "]" 0 0 0
369 0 ▶ --$hsh_level if $rc eq "}";
Branch: 1 branch
BranchTrueFalseTotal
if $rc eq "}" 0 0 0
370 0 ▶ if (($level == 0 || ($rc eq "(" && $level == 1)) && $sq_level == 0 && $hsh_level == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level == 0 || $rc eq "(" && $level == 1 and $sq_level == 0 and $hsh_level == 0) 0 0 0
Condition0%0/12
$level == 0 || $rc eq "(" && $level == 1 and $sq_level == 0 and $hsh_level == 0
!ll&&!rl&&r
000
$level == 0 || $rc eq "(" && $level == 1 and $sq_level == 0
!ll&&!rl&&r
000
$level == 0 or $rc eq "(" and $level == 1
l!l&&r!l&&!r
000
$rc eq "(" and $level == 1
!ll&&!rl&&r
000
MC/DC0%0/5
$level == 0 || $rc eq "(" && $level == 1 and $sq_level == 0 and $hsh_level == 0
$level == 0 $rc eq "(" $level == 1 $sq_level == 0 $hsh_level == 0
Truth table0%0/8
A or B and C and D and E
A= $level == 0B= $rc eq "("C= $level == 1D= $sq_level == 0E= $hsh_level == 0
ABCDEresult
00XXX0
010XX0
1XX0X0
0110X0
1XX100
011100
1XX111
011111
371 # If we're only spaces, that means we're a new a token.
372 0 ▶ if ($rc eq "(" || defined $whitespace || $nword_op) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rc eq "(" or defined $whitespace or $nword_op) 0 0 0
Condition0%0/6
$rc eq "(" or defined $whitespace or $nword_op
l!l&&r!l&&!r
000
$rc eq "(" or defined $whitespace
l!l&&r!l&&!r
000
MC/DC0%0/3
$rc eq "(" or defined $whitespace or $nword_op
$rc eq "(" defined $whitespace $nword_op
Truth table0%0/4
A or B or C
A= $rc eq "("B= defined $whitespaceC= $nword_op
ABCresult
1XX1
01X1
0011
0000
373 0 ▶ if (defined $start_space) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $start_space) 0 0 0
374 0 my $contents = substr($exp, $start_space, $rs - $start_space);
375 0 ▶ push(@tokens, $self->parse_token([$line->[0], $line->[1] + $start_space, $line->[2] + $start_space, $line->[4]], $contents)) if $contents !~ m/^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $contents =~ /^\s*$/ 0 0 0
376 }
377 0 ▶ push(@tokens, $self->parse_token([$line->[0], $line->[1] + $start_space, $line->[2] + $start_space, $line->[4]], $nword_op)) if $nword_op;
Branch: 1 branch
BranchTrueFalseTotal
if $nword_op 0 0 0
378 0 $start_space = $re;
379 }
380 }
381 }
382 0 ▶ $squot = !$squot if ($rc eq "'" && !$dquot);
Branch: 1 branch
BranchTrueFalseTotal
if $rc eq "'" and not $dquot 0 0 0
Condition0%0/3
$rc eq "'" and not $dquot
!ll&&!rl&&r
000
MC/DC0%0/2
$rc eq "'" and not $dquot
$rc eq "'" not $dquot
Truth table0%0/3
A and not(B)
A= $rc eq "'"B= not $dquot
ABresult
0X0
100
111
383 0 ▶ $dquot = !$dquot if ($rc eq '"' && !$squot);
Branch: 1 branch
BranchTrueFalseTotal
if $rc eq "\"" and not $squot 0 0 0
Condition0%0/3
$rc eq "\"" and not $squot
!ll&&!rl&&r
000
MC/DC0%0/2
$rc eq "\"" and not $squot
$rc eq "\"" not $squot
Truth table0%0/3
A and not(B)
A= $rc eq "\""B= not $squot
ABresult
0X0
100
111
384 }
385 0 ▶ die WWW::Shopify::Liquid::Exception::Lexer::UnbalancedBrace->new($line) unless $level == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $level == 0 0 0 0
386 # Go through and combine any -1 from OP NUM to NUM.
387 my @ids = grep {
388 0 $tokens[$_]->isa('WWW::Shopify::Liquid::Token::Number') &&
389 0 ▶ $tokens[$_-1]->isa('WWW::Shopify::Liquid::Token::Operator') && $tokens[$_-1]->{core} eq "-" &&
Branch: 1 branch
BranchTrueFalseTotal
$tokens[$_]->isa("WWW::Shopify::Liquid::Token::Number") and $tokens[$_ - 1]->isa("WWW::Shopify::Liquid::Token::Operator") and $tokens[$_ - 1]{"core"} eq "-" and $_ == 1 || $tokens[$_ - 2]->isa("WWW::Shopify::Liquid::Token::Separator") || $tokens[$_ - 2]->isa("WWW::Shopify::Liquid::Token::Operator") 0 0 0
Condition0%0/15
$tokens[$_]->isa('WWW::Shopify::Liquid::Token::Number') && $tokens[$_ - 1]->isa('WWW::Shopify::Liquid::Token::Operator') && $tokens[$_ - 1]{'core'} eq '-' && ($_ == 1 || $tokens[$_ - 2]->isa('WWW::Shopify::Liquid::Token::Separator') || $tokens[$_ - 2]->isa('WWW::Shopify::Liquid::Token::Operator'))
!ll&&!rl&&r
000
$tokens[$_]->isa("WWW::Shopify::Liquid::Token::Number") and $tokens[$_ - 1]->isa("WWW::Shopify::Liquid::Token::Operator") and $tokens[$_ - 1]{"core"} eq "-"
!ll&&!rl&&r
000
$tokens[$_]->isa("WWW::Shopify::Liquid::Token::Number") and $tokens[$_ - 1]->isa("WWW::Shopify::Liquid::Token::Operator")
!ll&&!rl&&r
000
$_ == 1 or $tokens[$_ - 2]->isa("WWW::Shopify::Liquid::Token::Separator") or $tokens[$_ - 2]->isa("WWW::Shopify::Liquid::Token::Operator")
l!l&&r!l&&!r
000
$_ == 1 or $tokens[$_ - 2]->isa("WWW::Shopify::Liquid::Token::Separator")
l!l&&r!l&&!r
000
MC/DC0%0/6
$tokens[$_]->isa('WWW::Shopify::Liquid::Token::Number') && $tokens[$_ - 1]->isa('WWW::Shopify::Liquid::Token::Operator') && $tokens[$_ - 1]{'core'} eq '-' && ($_ == 1 || $tokens[$_ - 2]->isa('WWW::Shopify::Liquid::Token::Separator') || $tokens[$_ - 2]->isa('WWW::Shopify::Liquid::Token::Operator'))
$tokens[$_]->isa("WWW::Shopify::Liquid::Token::Number") $tokens[$_ - 1]->isa("WWW::Shopify::Liquid::Token::Operator") $tokens[$_ - 1]{"core"} eq "-" $_ == 1 $tokens[$_ - 2]->isa("WWW::Shopify::Liquid::Token::Separator") $tokens[$_ - 2]->isa("WWW::Shopify::Liquid::Token::Operator")
Truth table0%0/7
A and B and C && D or E or F
A= $tokens[$_]->isa("WWW::Shopify::Liquid::Token::Number")B= $tokens[$_ - 1]->isa("WWW::Shopify::Liquid::Token::Operator")C= $tokens[$_ - 1]{"core"} eq "-"D= $_ == 1E= $tokens[$_ - 2]->isa("WWW::Shopify::Liquid::Token::Separator")F= $tokens[$_ - 2]->isa("WWW::Shopify::Liquid::Token::Operator")
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110000
1111XX1
11101X1
1110011
390 ($_ == 1 || $tokens[$_-2]->isa('WWW::Shopify::Liquid::Token::Separator') || $tokens[$_-2]->isa('WWW::Shopify::Liquid::Token::Operator'))
391 } 1..$#tokens;
392 0 for (@ids) { $tokens[$_]->{core} *= -1; $tokens[$_-1] = undef; }
393 0 @tokens = grep { defined $_ } @tokens;
394 # Go through and combine colon separated arguments into named arguments.
395 @ids = grep {
396 0 ($_ == 2 || !$tokens[$_-3]->isa('WWW::Shopify::Liquid::Token::Operator') || $tokens[$_-3]->{core} ne "|") &&
397 0 $tokens[$_-2]->isa('WWW::Shopify::Liquid::Token::Variable') && int(@{$tokens[$_-2]->{core}}) == 1 && $tokens[$_-2]->{core}->[0]->isa('WWW::Shopify::Liquid::Token::String') &&
398 0 ▶ $tokens[$_-1]->isa('WWW::Shopify::Liquid::Token::Separator') && $tokens[$_-1]->{core} eq ":" &&
Branch: 1 branch
BranchTrueFalseTotal
$_ == 2 || !$tokens[$_ - 3]->isa("WWW::Shopify::Liquid::Token::Operator") || $tokens[$_ - 3]{"core"} ne "|" and $tokens[$_ - 2]->isa("WWW::Shopify::Liquid::Token::Variable") and int @{$tokens[$_ - 2]{"core"};} == 1 and $tokens[$_ - 2]{"core"}[0]->isa("WWW::Shopify::Liquid::Token::String") and $tokens[$_ - 1]->isa("WWW::Shopify::Liquid::Token::Separator") and $tokens[$_ - 1]{"core"} eq ":" and $tokens[$_]->isa("WWW::Shopify::Liquid::Token::Operand") 0 0 0
Condition0%0/21
$_ == 2 || !$tokens[$_ - 3]->isa("WWW::Shopify::Liquid::Token::Operator") || $tokens[$_ - 3]{"core"} ne "|" and $tokens[$_ - 2]->isa("WWW::Shopify::Liquid::Token::Variable") and int @{$tokens[$_ - 2]{"core"};} == 1 and $tokens[$_ - 2]{"core"}[0]->isa("WWW::Shopify::Liquid::Token::String") and $tokens[$_ - 1]->isa("WWW::Shopify::Liquid::Token::Separator") and $tokens[$_ - 1]{"core"} eq ":"
!ll&&!rl&&r
000
$_ == 2 || !$tokens[$_ - 3]->isa("WWW::Shopify::Liquid::Token::Operator") || $tokens[$_ - 3]{"core"} ne "|" and $tokens[$_ - 2]->isa("WWW::Shopify::Liquid::Token::Variable") and int @{$tokens[$_ - 2]{"core"};} == 1 and $tokens[$_ - 2]{"core"}[0]->isa("WWW::Shopify::Liquid::Token::String") and $tokens[$_ - 1]->isa("WWW::Shopify::Liquid::Token::Separator")
!ll&&!rl&&r
000
$_ == 2 || !$tokens[$_ - 3]->isa("WWW::Shopify::Liquid::Token::Operator") || $tokens[$_ - 3]{"core"} ne "|" and $tokens[$_ - 2]->isa("WWW::Shopify::Liquid::Token::Variable") and int @{$tokens[$_ - 2]{"core"};} == 1 and $tokens[$_ - 2]{"core"}[0]->isa("WWW::Shopify::Liquid::Token::String")
!ll&&!rl&&r
000
$_ == 2 || !$tokens[$_ - 3]->isa("WWW::Shopify::Liquid::Token::Operator") || $tokens[$_ - 3]{"core"} ne "|" and $tokens[$_ - 2]->isa("WWW::Shopify::Liquid::Token::Variable") and int @{$tokens[$_ - 2]{"core"};} == 1
!ll&&!rl&&r
000
$_ == 2 || !$tokens[$_ - 3]->isa("WWW::Shopify::Liquid::Token::Operator") || $tokens[$_ - 3]{"core"} ne "|" and $tokens[$_ - 2]->isa("WWW::Shopify::Liquid::Token::Variable")
!ll&&!rl&&r
000
$_ == 2 or not $tokens[$_ - 3]->isa("WWW::Shopify::Liquid::Token::Operator") or $tokens[$_ - 3]{"core"} ne "|"
l!l&&r!l&&!r
000
$_ == 2 or not $tokens[$_ - 3]->isa("WWW::Shopify::Liquid::Token::Operator")
l!l&&r!l&&!r
000
MC/DC0%0/8
$_ == 2 || !$tokens[$_ - 3]->isa("WWW::Shopify::Liquid::Token::Operator") || $tokens[$_ - 3]{"core"} ne "|" and $tokens[$_ - 2]->isa("WWW::Shopify::Liquid::Token::Variable") and int @{$tokens[$_ - 2]{"core"};} == 1 and $tokens[$_ - 2]{"core"}[0]->isa("WWW::Shopify::Liquid::Token::String") and $tokens[$_ - 1]->isa("WWW::Shopify::Liquid::Token::Separator") and $tokens[$_ - 1]{"core"} eq ":"
$_ == 2 not $tokens[$_ - 3]->isa("WWW::Shopify::Liquid::Token::Operator") $tokens[$_ - 3]{"core"} ne "|" $tokens[$_ - 2]->isa("WWW::Shopify::Liquid::Token::Variable") int @{$tokens[$_ - 2]{"core"};} == 1 $tokens[$_ - 2]{"core"}[0]->isa("WWW::Shopify::Liquid::Token::String") $tokens[$_ - 1]->isa("WWW::Shopify::Liquid::Token::Separator") $tokens[$_ - 1]{"core"} eq ":"
Truth table0%0/19
A or not(B) or C and D and E and F and G and H
A= $_ == 2B= not $tokens[$_ - 3]->isa("WWW::Shopify::Liquid::Token::Operator")C= $tokens[$_ - 3]{"core"} ne "|"D= $tokens[$_ - 2]->isa("WWW::Shopify::Liquid::Token::Variable")E= int @{$tokens[$_ - 2]{"core"};} == 1F= $tokens[$_ - 2]{"core"}[0]->isa("WWW::Shopify::Liquid::Token::String")G= $tokens[$_ - 1]->isa("WWW::Shopify::Liquid::Token::Separator")H= $tokens[$_ - 1]{"core"} eq ":"
ABCDEFGHresult
000XXXXX0
1XX0XXXX0
01X0XXXX0
0010XXXX0
1XX10XXX0
01X10XXX0
00110XXX0
1XX110XX0
01X110XX0
001110XX0
1XX1110X0
01X1110X0
0011110X0
1XX111100
01X111100
001111100
1XX111111
01X111111
001111111
399 $tokens[$_]->isa('WWW::Shopify::Liquid::Token::Operand')
400 } (2..$#tokens);
401 0 for (@ids) { $tokens[$_] = WWW::Shopify::Liquid::Token::Variable::Named->new($line, $tokens[$_-2]->{core}->[0]->{core}, $tokens[$_]); $tokens[$_-2] = undef; $tokens[$_-1] = undef; }
402 0 @tokens = grep { defined $_ } @tokens;
403 0 return @tokens;
404 }
405  
406 sub parse_text {
407 0 ▶ my ($self, $text) = @_;
Subroutine parse_text: not called CC=40 SCAR=73.5
Pod undocumented
408 0 ▶ return () unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 0 0
409 0 my @tokens = ();
410
411 0 my $line = 1;
412 0 my $line_position = 0;
413
414 0 my $lexing_halter;
415 my $open_control_tag;
416 0 my $open_output_tag;
417 0 my $open_single_quote;
418 0 my $open_double_quote;
419 0 my $strip_left;
420
421 0 my $end_offset = 0;
422 0 my $start_position = [1, 0, 0];
423
424 # This is a substitution instead of a simple match, because very long perl native UTF8 strings, are variable length
425 # meaning any substr, or index operations need to walk the string in order to complete. This is like an o(n^2) consequence
426 # so it's fine at smaller lengths, but at larger lengths, it's infeasible to call substr on far offsets with any significant
427 # frequency. So we eat the string as we process it. Possibly slightly slower than simple matching on byte-strings, but way
428 # faster on UTF-8, and at this point in my life, I just want consistency rather than best-possible-performance (this would because
429 # written in D -betterC if I was interested in best possible performance at this point.)
430 0 my $accumulator = '';
431 # Step 1. We only care about new lines (to count what line we're on), {% and {{.
432 0 my $count = 0;
433 28 ▶ use Time::HiRes qw(time);
Subroutine BEGIN: called CC=1 SCAR=0.0
434 0 my $start = time;
435 0 ▶ while ($text =~ s/^(.*?)(?:(\{\{\-?)|({%\-?))//s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ s/^(.*?)(?:(\{\{\-?)|({%\-?))//s) 0 0 0
436 0 $end_offset += $+[0];
437 # These variables are entirely boolean flags.
438 0 my ($start_output_tag, $start_control_tag) = ($2, $3);
439 0 $accumulator .= $1;
440 0 ▶ if ($accumulator ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($accumulator ne "") 0 0 0
441 # Count the number of lines in the accumulator, to ensure we have the approrpiate line position.
442 0 $line += ($accumulator =~ tr/\r?\n//);
443 0 $line_position = rindex($accumulator, "\n") + $start_position->[2] + 1;
444 }
445 0 ▶ $open_control_tag = [$line, $end_offset - length($start_control_tag) - $line_position, $end_offset - length($start_control_tag), $self->file_context] if $start_control_tag;
Branch: 1 branch
BranchTrueFalseTotal
if $start_control_tag 0 0 0
446 0 ▶ $open_output_tag = [$line, $end_offset - length($start_output_tag) - $line_position, $end_offset - length($start_output_tag), $self->file_context] if $start_output_tag;
Branch: 1 branch
BranchTrueFalseTotal
if $start_output_tag 0 0 0
447 0 ▶ $strip_left = index($start_control_tag || $start_output_tag, "-") != -1;
Condition0%0/3
$start_control_tag || $start_output_tag
l!l&&r!l&&!r
000
MC/DC0%0/2
$start_control_tag || $start_output_tag
$start_control_tag $start_output_tag
Truth table0%0/3
A || B
A= $start_control_tagB= $start_output_tag
ABresult
1X1
011
000
448
449 0 ▶ $accumulator =~ s/^\s*// if int(@tokens) > 0 && $tokens[-1]->{strip_right};
Branch: 1 branch
BranchTrueFalseTotal
if int @tokens > 0 and $tokens[-1]{"strip_right"} 0 0 0
Condition0%0/3
int @tokens > 0 and $tokens[-1]{"strip_right"}
!ll&&!rl&&r
000
MC/DC0%0/2
int @tokens > 0 and $tokens[-1]{"strip_right"}
int @tokens > 0 $tokens[-1]{"strip_right"}
Truth table0%0/3
A and B
A= int @tokens > 0B= $tokens[-1]{"strip_right"}
ABresult
0X0
100
111
450 0 ▶ $accumulator =~ s/\s*$// if $strip_left;
Branch: 1 branch
BranchTrueFalseTotal
if $strip_left 0 0 0
451 0 ▶ if ($accumulator ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($accumulator ne "") 0 0 0
452 # Count the number of lines in the accumulator.
453 0 push(@tokens, WWW::Shopify::Liquid::Token::Text->new($start_position, $accumulator));
454 0 $accumulator = '';
455 }
456 0 ▶ last if $text eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $text eq "" 0 0 0
457 0 $start_position = [$line, $end_offset - $line_position, $end_offset, $self->file_context];
458
459 # Step 2. If we have an open tag, we parse out tokens from argument context inside that tag.
460 0 ▶ while ($text =~ s/(.*?)(?:(\")|(\')|(\-?%})|(\-?\}\})|(\r?\n))//s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ s/(.*?)(?:(\")|(\')|(\-?%})|(\-?\}\})|(\r?\n))//s) 0 0 0
461 0 my ($double_quote, $single_quote, $end_control_tag, $end_output_tag, $newline) = ($2, $3, $4, $5, $6);
462 0 $end_offset += $+[0];
463
464 0 ▶ if (!$open_single_quote && !$open_double_quote && ($end_output_tag || $end_control_tag)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $open_single_quote || $open_double_quote and $end_output_tag || $end_control_tag) { } 0 0 0
Condition0%0/9
not $open_single_quote || $open_double_quote and $end_output_tag || $end_control_tag
!ll&&!rl&&r
000
$open_single_quote || $open_double_quote
l!l&&r!l&&!r
000
$end_output_tag or $end_control_tag
l!l&&r!l&&!r
000
MC/DC0%0/4
not $open_single_quote || $open_double_quote and $end_output_tag || $end_control_tag
$open_single_quote $open_double_quote $end_output_tag $end_control_tag
Truth table0%0/5
not(A || B) and C or D
A= $open_single_quoteB= $open_double_quoteC= $end_output_tagD= $end_control_tag
ABCDresult
1XXX0
01XX0
00000
001X1
00011
465 0 ▶ my $strip_right = index($end_control_tag || $end_output_tag, "-") != -1;
Condition0%0/3
$end_control_tag || $end_output_tag
l!l&&r!l&&!r
000
MC/DC0%0/2
$end_control_tag || $end_output_tag
$end_control_tag $end_output_tag
Truth table0%0/3
A || B
A= $end_control_tagB= $end_output_tag
ABresult
1X1
011
000
466 0 $accumulator .= $1;
467 0 ▶ if ($end_output_tag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($end_output_tag) { } 0 0 0
468 0 ▶ die new WWW::Shopify::Liquid::Exception::Lexer::UnbalancedControlTag($open_control_tag) if $open_control_tag;
Branch: 1 branch
BranchTrueFalseTotal
if $open_control_tag 0 0 0
469 0 push(@tokens, WWW::Shopify::Liquid::Token::Output->new($open_output_tag, [$self->parse_expression($start_position, $accumulator)], $strip_left, $strip_right));
470 0 $open_output_tag = undef;
471 } else {
472 0 ▶ die new WWW::Shopify::Liquid::Exception::Lexer::UnbalancedOutputTag($open_output_tag) if $open_output_tag;
Branch: 1 branch
BranchTrueFalseTotal
if $open_output_tag 0 0 0
473 0 ▶ die new WWW::Shopify::Liquid::Exception::Lexer::Tag($start_position, $accumulator) if $accumulator !~ m/^\s*(\w+)\s*(.*?)\s*$/s;
Branch: 1 branch
BranchTrueFalseTotal
unless $accumulator =~ /^\s*(\w+)\s*(.*?)\s*$/s 0 0 0
474 0 push(@tokens, WWW::Shopify::Liquid::Token::Tag->new($open_control_tag, $1, [$self->parse_expression($start_position, $2)], $strip_left, $strip_right));
475 0 ▶ $lexing_halter = $tokens[-1] if $self->{lexing_halters}->{$1};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"lexing_halters"}{$1} 0 0 0
476 0 $open_control_tag = undef;
477 }
478 0 $accumulator = '';
479 0 $start_position = [$line, $end_offset - $line_position, $end_offset, $self->file_context];
480 0 last;
481 } else {
482 0 ▶ if ($newline) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newline) 0 0 0
483 0 ++$line;
484 0 $line_position = $end_offset;
485 }
486 0 ▶ $open_single_quote = !$open_single_quote if $single_quote && !$open_double_quote;
Branch: 1 branch
BranchTrueFalseTotal
if $single_quote and not $open_double_quote 0 0 0
Condition0%0/3
$single_quote and not $open_double_quote
!ll&&!rl&&r
000
MC/DC0%0/2
$single_quote and not $open_double_quote
$single_quote not $open_double_quote
Truth table0%0/3
A and not(B)
A= $single_quoteB= not $open_double_quote
ABresult
0X0
100
111
487 0 ▶ $open_double_quote = !$open_double_quote if $double_quote && !$open_single_quote;
Branch: 1 branch
BranchTrueFalseTotal
if $double_quote and not $open_single_quote 0 0 0
Condition0%0/3
$double_quote and not $open_single_quote
!ll&&!rl&&r
000
MC/DC0%0/2
$double_quote and not $open_single_quote
$double_quote not $open_single_quote
Truth table0%0/3
A and not(B)
A= $double_quoteB= not $open_single_quote
ABresult
0X0
100
111
488 0 $accumulator .= $&;
489 }
490 }
491 # For lexing halters, consume everything up to the next end tag explicitly.
492 0 ▶ if ($lexing_halter) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lexing_halter) 0 0 0
493 0 my $core = $lexing_halter->{tag};
494 0 ▶ while ($text =~ s/(.*?)(?:({%\-?\s*end$core\s*\-?%})|(\r?\n))//s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ s/(.*?)(?:({%\-?\s*end$core\s*\-?%})|(\r?\n))//s) 0 0 0
495 0 ▶ if ($3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($3) { } 0 0 0
496 0 ++$line;
497 0 $line_position = $end_offset;
498 0 $accumulator .= $1 . $3;
499 } else {
500 0 $accumulator .= $1;
501 0 ▶ push(@tokens, WWW::Shopify::Liquid::Token::Text->new($start_position, $accumulator)) if $accumulator ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $accumulator ne "" 0 0 0
502 0 push(@tokens, WWW::Shopify::Liquid::Token::Tag->new($start_position, "end$core", []));
503 0 $accumulator = '';
504 0 $lexing_halter = undef;
505 0 last;
506 }
507 }
508 }
509 }
510 0 ▶ die new WWW::Shopify::Liquid::Exception::Lexer::UnbalancedSingleQuote($open_single_quote) if $open_single_quote;
Branch: 1 branch
BranchTrueFalseTotal
if $open_single_quote 0 0 0
511 0 ▶ die new WWW::Shopify::Liquid::Exception::Lexer::UnbalancedDoubleQuote($open_double_quote) if $open_double_quote;
Branch: 1 branch
BranchTrueFalseTotal
if $open_double_quote 0 0 0
512 0 ▶ die new WWW::Shopify::Liquid::Exception::Lexer::UnbalancedLexingHalt($lexing_halter) if $lexing_halter;
Branch: 1 branch
BranchTrueFalseTotal
if $lexing_halter 0 0 0
513 0 ▶ die new WWW::Shopify::Liquid::Exception::Lexer::UnbalancedControlTag($open_control_tag) if $open_control_tag;
Branch: 1 branch
BranchTrueFalseTotal
if $open_control_tag 0 0 0
514 0 ▶ die new WWW::Shopify::Liquid::Exception::Lexer::UnbalancedOutputTag($open_output_tag) if $open_output_tag;
Branch: 1 branch
BranchTrueFalseTotal
if $open_output_tag 0 0 0
515 0 $accumulator .= $text;
516 0 ▶ $accumulator =~ s/^\s*// if int(@tokens) > 0 && $tokens[-1]->{strip_right};
Branch: 1 branch
BranchTrueFalseTotal
if int @tokens > 0 and $tokens[-1]{"strip_right"} 0 0 0
Condition0%0/3
int @tokens > 0 and $tokens[-1]{"strip_right"}
!ll&&!rl&&r
000
MC/DC0%0/2
int @tokens > 0 and $tokens[-1]{"strip_right"}
int @tokens > 0 $tokens[-1]{"strip_right"}
Truth table0%0/3
A and B
A= int @tokens > 0B= $tokens[-1]{"strip_right"}
ABresult
0X0
100
111
517 0 ▶ push(@tokens, WWW::Shopify::Liquid::Token::Text->new($start_position, $accumulator)) if $accumulator ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $accumulator ne "" 0 0 0
518 0 return @tokens;
519 }
520  
521 sub unparse_token {
522 0 ▶ my ($self, $token) = @_;
Subroutine unparse_token: not called CC=13 SCAR=52.0
Pod undocumented
523 0 ▶ return "null" if !defined $token;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $token 0 0 0
524 0 ▶ return '' if $token eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $token eq "" 0 0 0
525 0 ▶ return "'" . do { $token =~ s/'/\\'/g; $token } . "'" if !blessed($token) && !looks_like_number($token);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($token) or &looks_like_number($token) 0 0 0
Condition0%0/3
builtin::blessed($token) or &looks_like_number($token)
l!l&&r!l&&!r
000
MC/DC0%0/2
builtin::blessed($token) or &looks_like_number($token)
builtin::blessed($token) &looks_like_number($token)
Truth table0%0/3
A or B
A= builtin::blessed($token)B= &looks_like_number($token)
ABresult
1X1
011
000
526 0 ▶ return $token unless blessed($token);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($token) 0 0 0
527 0 ▶ return "null" if $token->isa('WWW::Shopify::Liquid::Token::NULL');
Branch: 1 branch
BranchTrueFalseTotal
if $token->isa("WWW::Shopify::Liquid::Token::NULL") 0 0 0
528 0 ▶ return '{}' if ($token->isa('WWW::Shopify::Liquid::Token::Hash'));
Branch: 1 branch
BranchTrueFalseTotal
if $token->isa("WWW::Shopify::Liquid::Token::Hash") 0 0 0
529 0 ▶ return '[]' if ($token->isa('WWW::Shopify::Liquid::Token::Array'));
Branch: 1 branch
BranchTrueFalseTotal
if $token->isa("WWW::Shopify::Liquid::Token::Array") 0 0 0
530 sub translate_variable {
531 0 ▶ my ($self, $token) = @_;
Subroutine translate_variable: not called CC=4 SCAR=30.0
Pod undocumented
532 my $variable = join(".", map {
533 !$self->is_processed($_) ? (
534 $_->isa('WWW::Shopify::Liquid::Token::Variable') ? ('[' . translate_variable($self, $_) . ']') :
535 ($_->isa('WWW::Shopify::Liquid::Token::Variable::Processing') ? $_->{core}->name : $_->{core})
536 0 ▶ ) : $_
Branch: 3 branches
BranchTrueFalseTotal
!$self->is_processed($_) ? : 0 0 0
$_->isa('WWW::Shopify::Liquid::Token::Variable') ? : 0 0 0
$_->isa('WWW::Shopify::Liquid::Token::Variable::Processing') ? : 0 0 0
537 0 } @{$token->{core}});
538 0 $variable =~ s/\.\[/\[/g;
539 0 return $variable;
540 }
541 0 ▶ return $token->{name} . ":" . $self->unparse_token($token->{core}) if ($token->isa('WWW::Shopify::Liquid::Token::Variable::Named'));
Branch: 1 branch
BranchTrueFalseTotal
if $token->isa("WWW::Shopify::Liquid::Token::Variable::Named") 0 0 0
542 0 ▶ return translate_variable($self, $token) if $token->isa('WWW::Shopify::Liquid::Token::Variable');
Branch: 1 branch
BranchTrueFalseTotal
if $token->isa("WWW::Shopify::Liquid::Token::Variable") 0 0 0
543 0 ▶ return "(" . join("", map { $self->unparse_token($_); } @{$token->{members}}) . ")" if $token->isa('WWW::Shopify::Liquid::Token::Grouping');
Branch: 1 branch
BranchTrueFalseTotal
if $token->isa("WWW::Shopify::Liquid::Token::Grouping") 0 0 0
544 0 ▶ return "'" . $token->{core} . "'" if $token->isa('WWW::Shopify::Liquid::Token::String');
Branch: 1 branch
BranchTrueFalseTotal
if $token->isa("WWW::Shopify::Liquid::Token::String") 0 0 0
545 0 return $token->{core};
546 }
547  
548 sub unparse_expression {
549 0 ▶ my ($self, @tokens) = @_;
Subroutine unparse_expression: not called CC=3 SCAR=24.8
Pod undocumented
550 0 ▶ my $a = join("", map { ($_ eq ":" || $_ eq ",") ? $_ : " " . $_; } grep { defined $_ } map { $self->unparse_token($_) } @tokens);
Branch: 1 branch
BranchTrueFalseTotal
$_ eq ':' || $_ eq ',' ? : 0 0 0
Condition0%0/3
$_ eq ":" or $_ eq ","
l!l&&r!l&&!r
000
MC/DC0%0/2
$_ eq ":" or $_ eq ","
$_ eq ":" $_ eq ","
Truth table0%0/3
A or B
A= $_ eq ":"B= $_ eq ","
ABresult
1X1
011
000
551 0 $a =~ s/^ //;
552 0 return $a;
553 }
554  
555 sub unparse_text_segment {
556 0 ▶ my ($self, $token) = @_;
Subroutine unparse_text_segment: not called CC=7 SCAR=40.3
Pod undocumented
557 0 ▶ my $space = $self->unparse_spaces ? " " : "";
Branch: 1 branch
BranchTrueFalseTotal
$self->unparse_spaces ? : 0 0 0
558 0 ▶ return $token if $self->is_processed($token);
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_processed($token) 0 0 0
559 0 ▶ if ($token->isa('WWW::Shopify::Liquid::Token::Tag')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->isa("WWW::Shopify::Liquid::Token::Tag")) 0 0 0
560 0 ▶ return "{%" . $space . $token->{tag} . $space . "%}" if !$token->{arguments} || int(@{$token->{arguments}}) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if not $token->{"arguments"} or int @{$token->{"arguments"};} == 0 0 0 0
Condition0%0/3
not $token->{"arguments"} or int @{$token->{"arguments"};} == 0
l!l&&r!l&&!r
000
MC/DC0%0/2
not $token->{"arguments"} or int @{$token->{"arguments"};} == 0
not $token->{"arguments"} int @{$token->{"arguments"};} == 0
Truth table0%0/3
not(A) or B
A= not $token->{"arguments"}B= int @{$token->{"arguments"};} == 0
ABresult
1X1
011
000
561 0 return "{%" . $space . $token->{tag} . " " . $self->unparse_expression(@{$token->{arguments}}) . $space . "%}";
562 }
563 0 ▶ return "{{" . $space . $self->unparse_expression(@{$token->{core}}) . $space . "}}" if $token->isa('WWW::Shopify::Liquid::Token::Output');
Branch: 1 branch
BranchTrueFalseTotal
if $token->isa("WWW::Shopify::Liquid::Token::Output") 0 0 0
564 0 return $token->{core};
565 }
566  
567 sub unparse_text {
568 0 ▶ my ($self, @tokens) = @_;
Subroutine unparse_text: not called CC=1 SCAR=6.9
Pod undocumented
569 0 return join('', grep { defined $_ } map { $self->unparse_text_segment($_) } @tokens);
570 }
571  
572 28 1;
↑ Summary blib/lib/WWW/Shopify/Liquid/Tag/Assign.pm »