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

filter: Statementstmt 10.0% 24 / 239 Branchbran 0.0% 0 / 130 Conditioncond 0.0% 0 / 66 MC/DCmcdc 0.0% 0 / 34 Subroutinesub 25.0% 8 / 32 Podpod n/a totaltotal 6.3% 32 / 501 CC 98 SCAR 60.8
CC
98
Cov
6%
parse_argument_tokens
992.0
parse_tokens
812.0
unparse_tokens
132.0
CRAP 437.9
« blib/lib/WWW/Shopify/Liquid/Tag/Assign.pm ↑ Summary blib/lib/WWW/Shopify/Liquid/Tag/Capture.pm »
1 #!/usr/bin/perl
2  
3 30 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 30 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package WWW::Shopify::Liquid::Parser;
7 30 ▶use base 'WWW::Shopify::Liquid::Pipeline';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 30 ▶use Module::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 30 ▶use List::MoreUtils qw(firstidx part);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 30 ▶use List::Util qw(first);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 30 ▶use WWW::Shopify::Liquid::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 useall WWW::Shopify::Liquid::Operator;
14 useall WWW::Shopify::Liquid::Tag;
15 useall WWW::Shopify::Liquid::Filter;
16  
17 0 ▶sub new { return bless {
Subroutine new: not called CC=1 SCAR=6.9
18 order_of_operations => [],
19 operators => {},
20 enclosing_tags => {},
21 free_tags => {},
22 filters => {},
23 inner_tags => {},
24 security => WWW::Shopify::Liquid::Security->new,
25 accept_unknown_filters => 0
26 }, $_[0]; }
27 0 ▶sub accept_unknown_filters { $_[0]->{accept_unknown_filters} = $_[1] if defined $_[1]; return $_[0]->{accept_unknown_filters}; }
Subroutine accept_unknown_filters: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[1] 0 0 0
28 0 ▶sub operator { return $_[0]->{operators}->{$_[1]}; }
Subroutine operator: not called CC=1 SCAR=6.9
29 0 ▶sub operators { return $_[0]->{operators}; }
Subroutine operators: not called CC=1 SCAR=6.9
30 0 ▶sub order_of_operations { return @{$_[0]->{order_of_operations}}; }
Subroutine order_of_operations: not called CC=1 SCAR=6.9
31 0 ▶sub free_tags { return $_[0]->{free_tags}; }
Subroutine free_tags: not called CC=1 SCAR=6.9
32 0 ▶sub enclosing_tags { return $_[0]->{enclosing_tags}; }
Subroutine enclosing_tags: not called CC=1 SCAR=6.9
33 0 ▶sub inner_tags { return $_[0]->{inner_tags}; }
Subroutine inner_tags: not called CC=1 SCAR=6.9
34 0 ▶sub filters { return $_[0]->{filters}; }
Subroutine filters: not called CC=1 SCAR=6.9
35  
36 sub register_tag {
37 0 ▶ $_[0]->free_tags->{$_[1]->name} = $_[1] if $_[1]->is_free;
Subroutine register_tag: not called CC=4 SCAR=30.0
Branch: 1 branch
BranchTrueFalseTotal
if $_[1]->is_free 0 0 0
38 0 ▶ if ($_[1]->is_enclosing) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1]->is_enclosing) 0 0 0
39 0 $_[0]->enclosing_tags->{$_[1]->name} = $_[1];
40 0 foreach my $tag ($_[1]->inner_tags) {
41 0 $_[0]->inner_tags->{$tag} = 1;
42 }
43 }
44 }
45  
46  
47 sub register_operator {
48 0 ▶ $_[0]->SUPER::register_operator($_[1]);
Subroutine register_operator: not called CC=3 SCAR=24.8
49 0 $_[0]->operators->{$_} = $_[1] for($_[1]->symbol);
50 0 my $ooo = $_[0]->{order_of_operations};
51 0 ▶ my $element = first { $_->[0]->priority == $_[1]->priority } @$ooo;
Subroutine __ANON__: not called CC=1 SCAR=6.9
52 0 ▶ if ($element) {
Branch: 1 branch
BranchTrueFalseTotal
if ($element) { } 0 0 0
53 0 push(@$element, $_[1]);
54 }
55 else {
56 0 push(@$ooo, [$_[1]]);
57 }
58 0 $_[0]->{order_of_operations} = [sort { $b->[0]->priority <=> $a->[0]->priority } @$ooo];
59 }
60 sub register_filter {
61 0 ▶ $_[0]->filters->{$_[1]->name} = $_[1];
Subroutine register_filter: not called CC=1 SCAR=6.9
62 }
63  
64  
65  
66 sub parse_filter_tokens {
67 0 ▶ my ($self, $initial, @tokens) = @_;
Subroutine parse_filter_tokens: not called CC=9 SCAR=45.0
68 0 my $filter = shift(@tokens);
69 0 my $filter_name = $filter->{core}->[0]->{core};
70 # TODO God, this is stupid, but temporary patch.
71 0 my $filter_package;
72 0 ▶ if ($filter_name =~ m/::/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filter_name =~ /::/) { } 0 0 0
73 0 $filter_package = $filter_name;
74 0 eval { $filter_package->name };
75 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
76 0 ▶ die new WWW::Shopify::Liquid::Exception::Parser::UnknownFilter($filter) if !$self->accept_unknown_filters;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->accept_unknown_filters 0 0 0
77 0 $filter_package = 'WWW::Shopify::Liquid::Filter::Unknown';
78 }
79 } else {
80 0 ▶ if (!$self->{filters}->{$filter_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{'filters'}{$filter_name}) { } 0 0 0
81 0 ▶ die new WWW::Shopify::Liquid::Exception::Parser::UnknownFilter($filter) if !$self->accept_unknown_filters;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->accept_unknown_filters 0 0 0
82 0 $filter_package = 'WWW::Shopify::Liquid::Filter::Unknown';
83 } else {
84 0 $filter_package = $self->{filters}->{$filter_name};
85 }
86 }
87 0 ▶ die new WWW::Shopify::Liquid::Exception::Parser::Arguments($filter, "In order to have arguments, filter must be followed by a colon.") if int(@tokens) > 0 && $tokens[0]->{core} ne ":";
Branch: 1 branch
BranchTrueFalseTotal
if int @tokens > 0 and $tokens[0]{"core"} ne ":" 0 0 0
Condition0%0/3
int @tokens > 0 and $tokens[0]{"core"} ne ":"
!ll&&!rl&&r
000
MC/DC0%0/2
int @tokens > 0 and $tokens[0]{"core"} ne ":"
int @tokens > 0 $tokens[0]{"core"} ne ":"
Truth table0%0/3
A and B
A= int @tokens > 0B= $tokens[0]{"core"} ne ":"
ABresult
0X0
100
111
88
89 0 my @arguments = ();
90 # Get rid of our colon.
91 0 ▶ if (shift(@tokens)) {
Branch: 1 branch
BranchTrueFalseTotal
if (shift @tokens) 0 0 0
92 0 my $i = 0;
93 0 ▶ @arguments = map { $self->parse_argument_tokens(grep { !$_->isa('WWW::Shopify::Liquid::Token::Separator') } @{$_}) } part { $i++ if $_->isa('WWW::Shopify::Liquid::Token::Separator') && $_->{core} eq ","; $i; } @tokens;
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
if $_->isa("WWW::Shopify::Liquid::Token::Separator") and $_->{"core"} eq "," 0 0 0
Condition0%0/3
$_->isa("WWW::Shopify::Liquid::Token::Separator") and $_->{"core"} eq ","
!ll&&!rl&&r
000
MC/DC0%0/2
$_->isa("WWW::Shopify::Liquid::Token::Separator") and $_->{"core"} eq ","
$_->isa("WWW::Shopify::Liquid::Token::Separator") $_->{"core"} eq ","
Truth table0%0/3
A and B
A= $_->isa("WWW::Shopify::Liquid::Token::Separator")B= $_->{"core"} eq ","
ABresult
0X0
100
111
94 }
95 0 $filter = $filter_package->new($initial->{line}, $filter_name, $initial, @arguments);
96 0 $filter->verify($self);
97 0 return $filter;
98 }
99 30 ▶use List::MoreUtils qw(part);
Subroutine BEGIN: called CC=1 SCAR=0.0
100  
101 # Similar, but doesn't deal with tags; deals solely with order of operations.
102 sub parse_argument_tokens {
103 0 ▶ my ($self, @argument_tokens) = @_;
Subroutine parse_argument_tokens: not called CC=31 SCAR=69.0
104
105 # Process all groupings.
106 0 ($argument_tokens[$_]) = $self->parse_argument_tokens($argument_tokens[$_]->members) for (grep { $argument_tokens[$_]->isa('WWW::Shopify::Liquid::Token::Grouping') } 0..$#argument_tokens);
107
108
109
110 # Process all groupings inside named variables.
111 0 ▶ ($_->{core}) = $self->parse_argument_tokens($_->{core}->members) for (grep { $_->isa('WWW::Shopify::Liquid::Token::Variable::Named') && $_->{core}->isa('WWW::Shopify::Liquid::Token::Grouping') } @argument_tokens);
Branch: 1 branch
BranchTrueFalseTotal
$_->isa("WWW::Shopify::Liquid::Token::Variable::Named") and $_->{"core"}->isa("WWW::Shopify::Liquid::Token::Grouping") 0 0 0
112 # Preprocess all variant filters.
113 0 for my $variable (grep { $_->isa('WWW::Shopify::Liquid::Token::Variable') } @argument_tokens) {
114 0 my @core = @{$variable->{core}};
115 0 ($variable->{core}->[$_]) = $self->parse_argument_tokens($core[$_]->members) for (grep { $core[$_]->isa('WWW::Shopify::Liquid::Token::Grouping') } 0..$#core);
116 }
117
118
119
120 # Process unary operators first; these have highest priority, regardless of what the priority field says.
121 0 ▶ while ((my $idx = firstidx { $_->isa('WWW::Shopify::Liquid::Token::Operator') && defined $_->{core} && $self->operator($_->{core}) && $self->operator($_->{core})->arity eq "unary" } @argument_tokens) != -1) {
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 2 branches
BranchTrueFalseTotal
if ((my $idx = &firstidx(sub { $_->isa("WWW::Shopify::Liquid::Token::Operator") and defined $_->{"core"} and $self->operator($_->{"core"}) and $self->operator($_->{"core"})->arity eq "unary"; } , @argument_tokens)) != -1) 0 0 0
$_->isa("WWW::Shopify::Liquid::Token::Operator") and defined $_->{"core"} and $self->operator($_->{"core"}) and $self->operator($_->{"core"})->arity eq "unary" 0 0 0
Condition0%0/6
$_->isa("WWW::Shopify::Liquid::Token::Operator") and defined $_->{"core"} and $self->operator($_->{"core"})
!ll&&!rl&&r
000
$_->isa("WWW::Shopify::Liquid::Token::Operator") and defined $_->{"core"}
!ll&&!rl&&r
000
MC/DC0%0/3
$_->isa("WWW::Shopify::Liquid::Token::Operator") and defined $_->{"core"} and $self->operator($_->{"core"})
$_->isa("WWW::Shopify::Liquid::Token::Operator") defined $_->{"core"} $self->operator($_->{"core"})
Truth table0%0/4
A and B and C
A= $_->isa("WWW::Shopify::Liquid::Token::Operator")B= defined $_->{"core"}C= $self->operator($_->{"core"})
ABCresult
0XX0
10X0
1100
1111
122 0 my $op = $argument_tokens[$idx];
123 0 my $fixness = $self->operator($argument_tokens[$idx]->{core})->fixness;
124 0 ▶ my $op1 = $fixness eq "postfix" ? $argument_tokens[$idx-1] : $argument_tokens[$idx+1];
Branch: 1 branch
BranchTrueFalseTotal
$fixness eq 'postfix' ? : 0 0 0
125 0 ▶ my $start = $fixness eq "potsfix" ? $idx-1 : $idx;
Branch: 1 branch
BranchTrueFalseTotal
$fixness eq 'potsfix' ? : 0 0 0
126 0 splice(@argument_tokens, $start, 2, $self->operator($argument_tokens[$idx]->{core})->new($op->{line}, $op->{core}, $op1));
127 }
128
129 # First, pull together filters. These are the highest priority operators, after parentheses. They also have their own weird syntax.
130 0 my $top = undef;
131
132 # Don't partition if we have any pipes. Pipes and multiple arguments don't play well together.
133 0 my @partitions;
134 0 my $has_pipe = 0;
135 0 ▶ if (int(grep { $_->isa('WWW::Shopify::Liquid::Token::Operator') && $_->{core} eq "|" } @argument_tokens) == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (int grep({$_->isa('WWW::Shopify::Liquid::Token::Operator') and $_->{'core'} eq '|';} @argument_tokens) == 0) { } 0 0 0
$_->isa("WWW::Shopify::Liquid::Token::Operator") and $_->{"core"} eq "|" 0 0 0
136 0 my $i = 0;
137 0 $has_pipe = 1;
138 0 ▶ @partitions = part { $i++ if $_->isa('WWW::Shopify::Liquid::Token::Separator'); $i; } @argument_tokens;
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if $_->isa("WWW::Shopify::Liquid::Token::Separator") 0 0 0
139 0 @partitions = map { my @n = grep { !$_->isa('WWW::Shopify::Liquid::Token::Separator') } @$_; \@n } @partitions;
140 } else {
141 0 @partitions = (\@argument_tokens);
142 }
143
144 0 my @tops;
145
146
147
148 0 foreach my $partition (@partitions) {
149 0 my @tokens = @$partition;
150 #@tokens = (grep { !$_->isa('WWW::Shopify::Liquid::Token::Separator') } @tokens) if !$has_pipe;
151
152 # Use the order of operations to create a binary tree structure.
153 0 foreach my $operators ($self->order_of_operations) {
154 0 my %ops = map { $_ => 1 } map { $_->symbol } @$operators;
155 # If we have pipes, we deal with those, and parse their lower level arguments first; this is an exception. Rewrite?
156 0 ▶ if ($operators->[0] eq 'WWW::Shopify::Liquid::Operator::Pipe') {
Branch: 1 branch
BranchTrueFalseTotal
if ($operators->[0] eq 'WWW::Shopify::Liquid::Operator::Pipe') { } 0 0 0
157 0 ▶ if ((my $idx = firstidx { $_->isa('WWW::Shopify::Liquid::Token::Operator') && $_->{core} eq "|" } @tokens) != -1) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 2 branches
BranchTrueFalseTotal
if ((my $idx = &firstidx(sub { $_->isa("WWW::Shopify::Liquid::Token::Operator") and $_->{"core"} eq "|"; } , @tokens)) != -1) 0 0 0
$_->isa("WWW::Shopify::Liquid::Token::Operator") and $_->{"core"} eq "|" 0 0 0
158 0 ▶ die new WWW::Shopify::Liquid::Exception::Parser($tokens[0]) if $idx == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $idx == 0 0 0 0
159 0 my $i = 0;
160 # Part should consist of the first token before a pipe, and then split on all pipes after this.,
161 0 ▶ my @parts = map { shift(@{$_}) if $_->[0]->{core} eq "|"; $_ } part { $i++ if $_->isa('WWW::Shopify::Liquid::Token::Operator') && $_->{core} eq "|"; $i; } splice(@tokens, $idx-1);
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 2 branches
BranchTrueFalseTotal
if $_->[0]{"core"} eq "|" 0 0 0
if $_->isa("WWW::Shopify::Liquid::Token::Operator") and $_->{"core"} eq "|" 0 0 0
Condition0%0/3
$_->isa("WWW::Shopify::Liquid::Token::Operator") and $_->{"core"} eq "|"
!ll&&!rl&&r
000
MC/DC0%0/2
$_->isa("WWW::Shopify::Liquid::Token::Operator") and $_->{"core"} eq "|"
$_->isa("WWW::Shopify::Liquid::Token::Operator") $_->{"core"} eq "|"
Truth table0%0/3
A and B
A= $_->isa("WWW::Shopify::Liquid::Token::Operator")B= $_->{"core"} eq "|"
ABresult
0X0
100
111
162 0 my $next = undef;
163 0 $top = $self->parse_filter_tokens($self->parse_argument_tokens(@{shift(@parts)}), @{shift(@parts)});
164 0 ▶ while (my $part = shift(@parts)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $part = shift @parts) 0 0 0
165 0 $top = $self->parse_filter_tokens($top, @$part);
166 }
167 0 push(@tokens, $top);
168 }
169 } else {
170 0 ▶ while ((my $idx = firstidx { $_->isa('WWW::Shopify::Liquid::Token::Operator') && exists $ops{$_->{core}} } @tokens) != -1) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 2 branches
BranchTrueFalseTotal
if ((my $idx = &firstidx(sub { $_->isa("WWW::Shopify::Liquid::Token::Operator") and exists $ops{$_->{"core"}}; } , @tokens)) != -1) 0 0 0
$_->isa("WWW::Shopify::Liquid::Token::Operator") and exists $ops{$_->{"core"}} 0 0 0
171 0 my ($op1, $op, $op2) = @tokens[$idx-1..$idx+1];
172 # The one exception would be if we have a - operator, and nothing before, this is unary negative operator, i.e. 0 - number.
173 0 ▶ die new WWW::Shopify::Liquid::Exception::Parser::Operands($tokens[0], $op1, $op, $op2) unless
Branch: 1 branch
BranchTrueFalseTotal
unless $idx > 0 and $idx < $#tokens and $op1->isa("WWW::Shopify::Liquid::Operator") || $op1->isa("WWW::Shopify::Liquid::Token::Operand") || $op1->isa("WWW::Shopify::Liquid::Filter") and $op2->isa("WWW::Shopify::Liquid::Operator") || $op2->isa("WWW::Shopify::Liquid::Token::Operand") || $op2->isa("WWW::Shopify::Liquid::Filter") 0 0 0
Condition0%0/21
$idx > 0 and $idx < $#tokens and $op1->isa("WWW::Shopify::Liquid::Operator") || $op1->isa("WWW::Shopify::Liquid::Token::Operand") || $op1->isa("WWW::Shopify::Liquid::Filter") and $op2->isa("WWW::Shopify::Liquid::Operator") || $op2->isa("WWW::Shopify::Liquid::Token::Operand") || $op2->isa("WWW::Shopify::Liquid::Filter")
!ll&&!rl&&r
000
$idx > 0 and $idx < $#tokens and $op1->isa("WWW::Shopify::Liquid::Operator") || $op1->isa("WWW::Shopify::Liquid::Token::Operand") || $op1->isa("WWW::Shopify::Liquid::Filter")
!ll&&!rl&&r
000
$idx > 0 and $idx < $#tokens
!ll&&!rl&&r
000
$op1->isa("WWW::Shopify::Liquid::Operator") or $op1->isa("WWW::Shopify::Liquid::Token::Operand") or $op1->isa("WWW::Shopify::Liquid::Filter")
l!l&&r!l&&!r
000
$op1->isa("WWW::Shopify::Liquid::Operator") or $op1->isa("WWW::Shopify::Liquid::Token::Operand")
l!l&&r!l&&!r
000
$op2->isa("WWW::Shopify::Liquid::Operator") or $op2->isa("WWW::Shopify::Liquid::Token::Operand") or $op2->isa("WWW::Shopify::Liquid::Filter")
l!l&&r!l&&!r
000
$op2->isa("WWW::Shopify::Liquid::Operator") or $op2->isa("WWW::Shopify::Liquid::Token::Operand")
l!l&&r!l&&!r
000
MC/DC0%0/8
$idx > 0 and $idx < $#tokens and $op1->isa("WWW::Shopify::Liquid::Operator") || $op1->isa("WWW::Shopify::Liquid::Token::Operand") || $op1->isa("WWW::Shopify::Liquid::Filter") and $op2->isa("WWW::Shopify::Liquid::Operator") || $op2->isa("WWW::Shopify::Liquid::Token::Operand") || $op2->isa("WWW::Shopify::Liquid::Filter")
$idx > 0 $idx < $#tokens $op1->isa("WWW::Shopify::Liquid::Operator") $op1->isa("WWW::Shopify::Liquid::Token::Operand") $op1->isa("WWW::Shopify::Liquid::Filter") $op2->isa("WWW::Shopify::Liquid::Operator") $op2->isa("WWW::Shopify::Liquid::Token::Operand") $op2->isa("WWW::Shopify::Liquid::Filter")
Truth table0%0/15
A and B and C or D or E and F or G or H
A= $idx > 0B= $idx < $#tokensC= $op1->isa("WWW::Shopify::Liquid::Operator")D= $op1->isa("WWW::Shopify::Liquid::Token::Operand")E= $op1->isa("WWW::Shopify::Liquid::Filter")F= $op2->isa("WWW::Shopify::Liquid::Operator")G= $op2->isa("WWW::Shopify::Liquid::Token::Operand")H= $op2->isa("WWW::Shopify::Liquid::Filter")
ABCDEFGHresult
0XXXXXXX0
10XXXXXX0
11000XXX0
111XX0000
1101X0000
110010000
111XX1XX1
111XX01X1
111XX0011
1101X1XX1
1101X01X1
1101X0011
110011XX1
1100101X1
110010011
174 $idx > 0 && $idx < $#tokens &&
175 ($op1->isa('WWW::Shopify::Liquid::Operator') || $op1->isa('WWW::Shopify::Liquid::Token::Operand') || $op1->isa('WWW::Shopify::Liquid::Filter')) &&
176 ($op2->isa('WWW::Shopify::Liquid::Operator') || $op2->isa('WWW::Shopify::Liquid::Token::Operand') || $op2->isa('WWW::Shopify::Liquid::Filter'));
177 0 ▶ ($op1) = $self->parse_argument_tokens($op1->members) if $op1->isa('WWW::Shopify::Liquid::Token::Grouping');
Branch: 1 branch
BranchTrueFalseTotal
if $op1->isa("WWW::Shopify::Liquid::Token::Grouping") 0 0 0
178 0 ▶ ($op2) = $self->parse_argument_tokens($op2->members) if $op2->isa('WWW::Shopify::Liquid::Token::Grouping');
Branch: 1 branch
BranchTrueFalseTotal
if $op2->isa("WWW::Shopify::Liquid::Token::Grouping") 0 0 0
179 0 splice(@tokens, $idx-1, 3, $self->operators->{$op->{core}}->new($op->{line}, $op->{core}, $op1, $op2));
180 }
181 }
182 }
183
184 # Only named variables can be without commas, for whatever reason. Goddammit shopify.
185 0 ▶ die new WWW::Shopify::Liquid::Exception::Parser::Operands(@tokens) unless int(grep { !$_->isa('WWW::Shopify::Liquid::Token::Variable::Named') } @tokens) == 1 || int(grep { !$_->isa('WWW::Shopify::Liquid::Token::Variable::Named') } @tokens) == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless int grep({not $_->isa("WWW::Shopify::Liquid::Token::Variable::Named");} @tokens) == 1 or int grep({not $_->isa("WWW::Shopify::Liquid::Token::Variable::Named");} @tokens) == 0 0 0 0
Condition0%0/3
int grep({not $_->isa("WWW::Shopify::Liquid::Token::Variable::Named");} @tokens) == 1 or int grep({not $_->isa("WWW::Shopify::Liquid::Token::Variable::Named");} @tokens) == 0
l!l&&r!l&&!r
000
MC/DC0%0/2
int grep({not $_->isa("WWW::Shopify::Liquid::Token::Variable::Named");} @tokens) == 1 or int grep({not $_->isa("WWW::Shopify::Liquid::Token::Variable::Named");} @tokens) == 0
int grep({not $_->isa("WWW::Shopify::Liquid::Token::Variable::Named");} @tokens) == 1 int grep({not $_->isa("WWW::Shopify::Liquid::Token::Variable::Named");} @tokens) == 0
Truth table0%0/3
A or B
A= int grep({not $_->isa("WWW::Shopify::Liquid::Token::Variable::Named");} @tokens) == 1B= int grep({not $_->isa("WWW::Shopify::Liquid::Token::Variable::Named");} @tokens) == 0
ABresult
1X1
011
000
186 0 push(@tops, @tokens);
187 }
188
189 0 return @tops;
190 }
191  
192 sub parse_tokens {
193 0 ▶ my ($self, @tokens) = @_;
Subroutine parse_tokens: not called CC=28 SCAR=67.0
194
195 0 ▶ return () if int(@tokens) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if int @tokens == 0 0 0 0
196
197 0 my @tags = ();
198 # First we take a look and start matching up opening and ending tags. Those which are free tags we can leave as is.
199 0 ▶ while (my $token = shift(@tokens)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = shift @tokens) 0 0 0
200 0 my $line = $token->{line};
201 0 ▶ if ($token->isa('WWW::Shopify::Liquid::Token::Tag')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token->isa('WWW::Shopify::Liquid::Token::Tag')) { } 0 0 0
elsif ($token->isa('WWW::Shopify::Liquid::Token::Output')) { } 0 0 0
202 0 my $tag = undef;
203 0 ▶ if ($self->enclosing_tags->{$token->tag}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->enclosing_tags->{$token->tag}) { } 0 0 0
elsif ($self->free_tags->{$token->tag}) { } 0 0 0
204 0 my @internal = ();
205 0 my @contents = ();
206 0 my %allowed_internal_tags = map { $_ => 1 } $self->enclosing_tags->{$token->tag}->inner_tags;
207 0 my $level = 1;
208 0 my $closed = undef;
209 0 for (0..$#tokens) {
210 0 ▶ if ($tokens[$_]->isa('WWW::Shopify::Liquid::Token::Tag')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens[$_]->isa("WWW::Shopify::Liquid::Token::Tag")) 0 0 0
211 0 ▶ if ($self->enclosing_tags->{$tokens[$_]->tag}) {
Branch: 4 branches
BranchTrueFalseTotal
if ($self->enclosing_tags->{$tokens[$_]->tag}) { } 0 0 0
elsif (exists $allowed_internal_tags{$tokens[$_]->tag} and $level == 1) { } 0 0 0
elsif ($tokens[$_]->tag eq 'end' . $token->tag and $level == 1) { } 0 0 0
elsif ($tokens[$_]->tag =~ /^end/) { } 0 0 0
212 0 ++$level;
213 ▶ } elsif (exists $allowed_internal_tags{$tokens[$_]->tag} && $level == 1) {
Condition0%0/3
exists $allowed_internal_tags{$tokens[$_]->tag} and $level == 1
!ll&&!rl&&r
000
MC/DC0%0/2
exists $allowed_internal_tags{$tokens[$_]->tag} and $level == 1
exists $allowed_internal_tags{$tokens[$_]->tag} $level == 1
Truth table0%0/3
A and B
A= exists $allowed_internal_tags{$tokens[$_]->tag}B= $level == 1
ABresult
0X0
100
111
214 0 $tokens[$_]->{arguments} = [$self->parse_argument_tokens(@{$tokens[$_]->{arguments}})];
215 0 push(@internal, $_);
216 ▶ } elsif ($tokens[$_]->tag eq "end" . $token->tag && $level == 1) {
Condition0%0/3
$tokens[$_]->tag eq 'end' . $token->tag and $level == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$tokens[$_]->tag eq 'end' . $token->tag and $level == 1
$tokens[$_]->tag eq 'end' . $token->tag $level == 1
Truth table0%0/3
A and B
A= $tokens[$_]->tag eq 'end' . $token->tagB= $level == 1
ABresult
0X0
100
111
217 0 --$level;
218 0 my $last_int = 0;
219 0 foreach my $int (@internal, $_) {
220 0 push(@contents, [splice(@tokens, 0, $int-$last_int)]);
221 0 ▶ shift(@{$contents[0]}) if $self->enclosing_tags->{$token->tag}->inner_ignore_whitespace && int(@contents) > 0 && int(@{$contents[0]}) > 0 && $contents[0]->[0]->isa('WWW::Shopify::Liquid::Token::Text::Whitespace');
Branch: 1 branch
BranchTrueFalseTotal
if $self->enclosing_tags->{$token->tag}->inner_ignore_whitespace and int @contents > 0 and int @{$contents[0];} > 0 and $contents[0][0]->isa("WWW::Shopify::Liquid::Token::Text::Whitespace") 0 0 0
Condition0%0/9
$self->enclosing_tags->{$token->tag}->inner_ignore_whitespace and int @contents > 0 and int @{$contents[0];} > 0 and $contents[0][0]->isa("WWW::Shopify::Liquid::Token::Text::Whitespace")
!ll&&!rl&&r
000
$self->enclosing_tags->{$token->tag}->inner_ignore_whitespace and int @contents > 0 and int @{$contents[0];} > 0
!ll&&!rl&&r
000
$self->enclosing_tags->{$token->tag}->inner_ignore_whitespace and int @contents > 0
!ll&&!rl&&r
000
MC/DC0%0/4
$self->enclosing_tags->{$token->tag}->inner_ignore_whitespace and int @contents > 0 and int @{$contents[0];} > 0 and $contents[0][0]->isa("WWW::Shopify::Liquid::Token::Text::Whitespace")
$self->enclosing_tags->{$token->tag}->inner_ignore_whitespace int @contents > 0 int @{$contents[0];} > 0 $contents[0][0]->isa("WWW::Shopify::Liquid::Token::Text::Whitespace")
Truth table0%0/5
A and B and C and D
A= $self->enclosing_tags->{$token->tag}->inner_ignore_whitespaceB= int @contents > 0C= int @{$contents[0];} > 0D= $contents[0][0]->isa("WWW::Shopify::Liquid::Token::Text::Whitespace")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
222 @contents = map {
223 0 my @array = @$_;
224 0 ▶ if (int(@array) > 0 && $array[0]->isa('WWW::Shopify::Liquid::Token::Tag') && $allowed_internal_tags{$array[0]->tag}) {
Branch: 1 branch
BranchTrueFalseTotal
if (int @array > 0 and $array[0]->isa('WWW::Shopify::Liquid::Token::Tag') and $allowed_internal_tags{$array[0]->tag}) { } 0 0 0
Condition0%0/6
int @array > 0 and $array[0]->isa("WWW::Shopify::Liquid::Token::Tag") and $allowed_internal_tags{$array[0]->tag}
!ll&&!rl&&r
000
int @array > 0 and $array[0]->isa("WWW::Shopify::Liquid::Token::Tag")
!ll&&!rl&&r
000
MC/DC0%0/3
int @array > 0 and $array[0]->isa("WWW::Shopify::Liquid::Token::Tag") and $allowed_internal_tags{$array[0]->tag}
int @array > 0 $array[0]->isa("WWW::Shopify::Liquid::Token::Tag") $allowed_internal_tags{$array[0]->tag}
Truth table0%0/4
A and B and C
A= int @array > 0B= $array[0]->isa("WWW::Shopify::Liquid::Token::Tag")C= $allowed_internal_tags{$array[0]->tag}
ABCresult
0XX0
10X0
1100
1111
225 0 [$array[0], $self->parse_tokens(@array[1..$#array])];
226 }
227 else {
228 0 [$self->parse_tokens(@array)]
229 }
230 } @contents;
231 0 $last_int = $int;
232 }
233 # Remove the endtag.
234 0 shift(@tokens);
235 0 $closed = 1;
236 0 last;
237 } elsif ($tokens[$_]->tag =~ m/^end/) {
238 0 --$level;
239 # TODO: Fix this whole thing; right now, no close tags are being spit out for the wrong tag. We do this to avoid an {% unless %}{% if %}{% else %}{% endif %}{% endunless%} situtation.
240 }
241 }
242 }
243 0 ▶ die new WWW::Shopify::Liquid::Exception::Parser::NoClose($token) unless $closed;
Branch: 1 branch
BranchTrueFalseTotal
unless $closed 0 0 0
244 0 $tag = $self->enclosing_tags->{$token->tag}->new($line, $token->tag, [$self->parse_argument_tokens(@{$token->{arguments}})], \@contents);
245 0 $tag->verify($self);
246 }
247 elsif ($self->free_tags->{$token->tag}) {
248 0 $tag = $self->free_tags->{$token->tag}->new($line, $token->tag, [$self->parse_argument_tokens(@{$token->{arguments}})]);
249 0 $tag->verify($self);
250 }
251 else {
252 0 ▶ die new WWW::Shopify::Liquid::Exception::Parser::NoOpen($token) if ($token->tag =~ m/^end(\w+)$/ && $self->enclosing_tags->{$1});
Branch: 1 branch
BranchTrueFalseTotal
if $token->tag =~ /^end(\w+)$/ and $self->enclosing_tags->{$1} 0 0 0
Condition0%0/3
$token->tag =~ /^end(\w+)$/ and $self->enclosing_tags->{$1}
!ll&&!rl&&r
000
MC/DC0%0/2
$token->tag =~ /^end(\w+)$/ and $self->enclosing_tags->{$1}
$token->tag =~ /^end(\w+)$/ $self->enclosing_tags->{$1}
Truth table0%0/3
A and B
A= $token->tag =~ /^end(\w+)$/B= $self->enclosing_tags->{$1}
ABresult
0X0
100
111
253 0 ▶ die new WWW::Shopify::Liquid::Exception::Parser::NakedInnerTag($token) if (exists $self->inner_tags->{$token->tag});
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->inner_tags->{$token->tag} 0 0 0
254 0 die new WWW::Shopify::Liquid::Exception::Parser::UnknownTag($token);
255 }
256 0 push(@tags, $tag);
257 }
258 elsif ($token->isa('WWW::Shopify::Liquid::Token::Output')) {
259 0 push(@tags, WWW::Shopify::Liquid::Tag::Output->new($line, [$self->parse_argument_tokens(@{$token->{core}})]));
260 }
261 else {
262 0 push(@tags, $token);
263 }
264 }
265
266 0 my $top = undef;
267 0 ▶ if (int(@tags) > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (int @tags > 1) { } 0 0 0
268 0 $top = WWW::Shopify::Liquid::Operator::Concatenate->new($tags[0]->{line}, '', @tags);
269 }
270 else {
271 0 ($top) = @tags;
272 }
273 0 return $top;
274 }
275  
276 sub unparse_argument_tokens {
277 0 ▶ my ($self, $ast) = @_;
Subroutine unparse_argument_tokens: not called CC=7 SCAR=40.3
278 0 ▶ return $ast if $self->is_processed($ast);
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_processed($ast) 0 0 0
279 0 ▶ if ($ast->isa('WWW::Shopify::Liquid::Filter')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ast->isa('WWW::Shopify::Liquid::Filter')) { } 0 0 0
elsif ($ast->isa('WWW::Shopify::Liquid::Operator')) { } 0 0 0
280 my @optokens = ($self->unparse_argument_tokens($ast->{operand}),
281 WWW::Shopify::Liquid::Token::Operator->new([0,0,0], '|'),
282 WWW::Shopify::Liquid::Token::Variable->new([0,0,0], WWW::Shopify::Liquid::Token::String->new([0,0,0], $ast->{core})),
283 0 ▶ (int(@{$ast->{arguments}}) > 0 ? (do {
Branch: 1 branch
BranchTrueFalseTotal
int @{$ast->{'arguments'};} > 0 ? : 0 0 0
284 0 my @args = @{$ast->{arguments}};
285 (
286 WWW::Shopify::Liquid::Token::Separator->new([0,0,0], ':'),
287 0 ▶ (map { (($_ > 0 ? (WWW::Shopify::Liquid::Token::Separator->new([0,0,0], ',')) : ()), $self->unparse_argument_tokens($args[$_])) } 0..$#args)
Branch: 1 branch
BranchTrueFalseTotal
$_ > 0 ? : 0 0 0
288 )
289 }) : ())
290 );
291 0 return @optokens;
292 } elsif ($ast->isa('WWW::Shopify::Liquid::Operator')) {
293 0 my @optokens = ($self->unparse_argument_tokens($ast->{operands}->[0]), WWW::Shopify::Liquid::Token::Operator->new([0,0,0], $ast->{core}), $self->unparse_argument_tokens($ast->{operands}->[1]));
294 0 ▶ return WWW::Shopify::Liquid::Token::Grouping->new([0,0,0], @optokens) if $ast->requires_grouping;
Branch: 1 branch
BranchTrueFalseTotal
if $ast->requires_grouping 0 0 0
295 0 return @optokens;
296 } else {
297 0 return $ast;
298 }
299 }
300  
301 sub unparse_tokens {
302 0 ▶ my ($self, $ast) = @_;
Subroutine unparse_tokens: not called CC=11 SCAR=48.8
303 0 ▶ return $ast if $self->is_processed($ast) || $ast->isa('WWW::Shopify::Liquid::Token');
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_processed($ast) or $ast->isa("WWW::Shopify::Liquid::Token") 0 0 0
Condition0%0/3
$self->is_processed($ast) or $ast->isa("WWW::Shopify::Liquid::Token")
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->is_processed($ast) or $ast->isa("WWW::Shopify::Liquid::Token")
$self->is_processed($ast) $ast->isa("WWW::Shopify::Liquid::Token")
Truth table0%0/3
A or B
A= $self->is_processed($ast)B= $ast->isa("WWW::Shopify::Liquid::Token")
ABresult
1X1
011
000
304 0 ▶ if ($ast->isa('WWW::Shopify::Liquid::Tag')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ast->isa("WWW::Shopify::Liquid::Tag")) 0 0 0
305 0 ▶ my @arguments = $ast->{arguments} ? $self->unparse_argument_tokens(@{$ast->{arguments}}) : ();
Branch: 1 branch
BranchTrueFalseTotal
$ast->{'arguments'} ? : 0 0 0
306 0 ▶ if ($ast->isa('WWW::Shopify::Liquid::Tag::Enclosing')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ast->isa('WWW::Shopify::Liquid::Tag::Enclosing')) { } 0 0 0
elsif ($ast->isa('WWW::Shopify::Liquid::Tag::Output')) { } 0 0 0
307 0 ▶ if ($ast->isa('WWW::Shopify::Liquid::Tag::If')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ast->isa('WWW::Shopify::Liquid::Tag::If')) { } 0 0 0
308 0 ▶ return (WWW::Shopify::Liquid::Token::Tag->new([0,0,0], $ast->{core}, \@arguments), $self->unparse_tokens($ast->{true_path}), WWW::Shopify::Liquid::Token::Tag->new([0,0,0], 'end' . $ast->{core})) if !$ast->{false_path};
Branch: 1 branch
BranchTrueFalseTotal
unless $ast->{"false_path"} 0 0 0
309 0 return (WWW::Shopify::Liquid::Token::Tag->new([0,0,0], $ast->{core}, \@arguments), $self->unparse_tokens($ast->{true_path}), WWW::Shopify::Liquid::Token::Tag->new([0,0,0], 'else'), $self->unparse_tokens($ast->{false_path}), WWW::Shopify::Liquid::Token::Tag->new([0,0,0], 'end'. $ast->{core}));
310 }
311 else {
312 0 return (WWW::Shopify::Liquid::Token::Tag->new([0,0,0], $ast->{core}, \@arguments), $self->unparse_tokens($ast->{contents}), WWW::Shopify::Liquid::Token::Tag->new([0,0,0], 'end' . $ast->{core}));
313 }
314 }
315 elsif ($ast->isa('WWW::Shopify::Liquid::Tag::Output')) {
316 0 return (WWW::Shopify::Liquid::Token::Output->new([0,0,0], [$self->unparse_argument_tokens(@{$ast->{arguments}})]));
317 }
318 else {
319 0 return (WWW::Shopify::Liquid::Token::Tag->new([0,0,0], $ast->{core}, \@arguments));
320 }
321 0 return $ast;
322 }
323 0 ▶ if ($ast->isa('WWW::Shopify::Liquid::Filter')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ast->isa("WWW::Shopify::Liquid::Filter")) 0 0 0
324 0 return $ast;
325 }
326 0 ▶ return (map { $self->unparse_tokens($_) } @{$ast->{operands}}) if ($ast->isa('WWW::Shopify::Liquid::Operator::Concatenate'));
Branch: 1 branch
BranchTrueFalseTotal
if $ast->isa("WWW::Shopify::Liquid::Operator::Concatenate") 0 0 0
327
328 }
329  
330 1;
« blib/lib/WWW/Shopify/Liquid/Tag/Assign.pm ↑ Summary blib/lib/WWW/Shopify/Liquid/Tag/Capture.pm »