lib/WWW/Shopify/Liquid/Lexer.pm

filter: Statementstmt 8.7% 22 / 252 Branchbran 0.0% 0 / 202 Conditioncond 0.0% 0 / 204 MC/DCmcdc 0.0% 0 / 104 Subroutinesub 30.4% 7 / 23 Podpod 0.0% 0 / 16 totaltotal 3.6% 29 / 801 CC 173 SCAR 75.5
CC
173
Cov
3%
parse_expression
3192.0
parse_token
2550.0
parse_text
1555.8
CRAP 1904.9
↑ Summary lib/WWW/Shopify/Liquid/Tag/Assign.pm »
1 #!/usr/bin/perl
2  
3 29 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 29 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 29 ▶use WWW::Shopify::Liquid::Token;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 package WWW::Shopify::Liquid::Lexer;
9 29 ▶use base 'WWW::Shopify::Liquid::Pipeline';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 29 ▶use Scalar::Util qw(looks_like_number blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 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
13 0 ▶sub operators { return $_[0]->{operators}; }
Subroutine operators: not called CC=1 SCAR=6.9
Pod undocumented
14 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
15 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
16 0 ▶sub register_operator { $_[0]->{operators}->{$_} = $_[1] for ($_[1]->symbol); }
Subroutine register_operator: not called CC=2 SCAR=17.9
Pod undocumented
17 0 ▶sub register_tag {
Subroutine register_tag: not called CC=3 SCAR=24.8
Pod undocumented
18 0 my ($self, $package) = @_;
19 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
20 }
21 0 ▶sub register_filter {
Subroutine register_filter: not called CC=2 SCAR=17.9
Pod undocumented
22 0 my ($self, $package) = @_;
23 0 ▶ $self->{transparent_filters}->{$package->name} = $package if ($package->transparent);
Branch: 1 branch
BranchTrueFalseTotal
if $package->transparent 0 0 0
24 }
25 0 ▶sub transparent_filters { return $_[0]->{transparent_filters}; }
Subroutine transparent_filters: not called CC=1 SCAR=6.9
Pod undocumented
26  
27 0 ▶sub parse_token {
Subroutine parse_token: not called CC=50 SCAR=78.4
Pod undocumented
28 0 my ($self, $line, $token) = @_;
29
30 # Strip token of whitespace.
31 0 ▶ return undef unless defined $token;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $token 0 0 0
32 0 $token =~ s/^\s*(.*?)\s*$/$1/;
33 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
34 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
35 0 my $string = $1;
36 0 ▶ if ($self->parse_escaped_characters) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->parse_escaped_characters) 0 0 0
37 0 $string =~ s/\\r/\r/g;
38 0 $string =~ s/\\n/\n/g;
39 0 $string =~ s/\\t/\t/g;
40 }
41 0 $string;
42 }) if $token =~ m/^'(.*)'$/s || $token =~ m/^"(.*)"$/s;
43 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
44 0 ▶ return WWW::Shopify::Liquid::Token::NULL->new() if $token eq 'null';
Branch: 1 branch
BranchTrueFalseTotal
if $token eq "null" 0 0 0
45 # return WWW::Shopify::Liquid::Token::Blank->new() if $token eq '';
46 # return WWW::Shopify::Liquid::Token::True->new() if $token eq 'true';
47 # return WWW::Shopify::Liquid::Token::False->new() if $token eq 'false';
48 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
49 0 ▶ return WWW::Shopify::Liquid::Token::Array->new($line) if ($token eq "[]");
Branch: 1 branch
BranchTrueFalseTotal
if $token eq "[]" 0 0 0
50 0 ▶ return WWW::Shopify::Liquid::Token::Hash->new($line) if ($token eq "{}");
Branch: 1 branch
BranchTrueFalseTotal
if $token eq "{}" 0 0 0
51 # We're a variable. Let's see what's going on. Split along non quoted . and [ ] fields.
52 0 my ($squot, $dquot, $start, @parts) = (0,0,0);
53 # customer['test']['b']
54 0 my $open_square_bracket = 0;
55 0 my $open_curly_bracket = 0;
56 0 ▶ while ($token =~ m/(\.|\[|\]|\{|\}|(?<!\\)\"|(?<!\\)\'|\b$)/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token =~ /(\.|\[|\]|\{|\}|(?<!\\)\"|(?<!\\)\'|\b$)/g) 0 0 0
57 0 my $sym = $&;
58 0 my $begin = $-[0];
59 0 my $end = $+[0];
60 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
61 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
62 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
63 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
64 0 my $contents = substr($token, $start, $begin - $start);
65
66 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
67 0 my @variables = ();
68 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
69 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
70 }
71 elsif ($sym eq "]") {
72 0 @variables = $self->parse_expression($line, $contents);
73 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
74 }
75 elsif ($sym eq "}") {
76 0 @variables = $self->parse_expression($line, $contents);
77 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
78 }
79 0 ▶ if (int(@variables) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (int @variables > 0) 0 0 0
80 0 ▶ if (int(@variables) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (int @variables == 1) { } 0 0 0
81 0 push(@parts, @variables);
82 }
83 else {
84 0 push(@parts, WWW::Shopify::Liquid::Token::Grouping->new($line, @variables)) ;
85 }
86 }
87 }
88 }
89 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
90 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
91 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
92
93 }
94 0 ▶ $squot = !$squot if $token eq "'";
Branch: 1 branch
BranchTrueFalseTotal
if $token eq "'" 0 0 0
95 0 ▶ $dquot = !$dquot if $token eq '"';
Branch: 1 branch
BranchTrueFalseTotal
if $token eq "\"" 0 0 0
96 }
97 0 return WWW::Shopify::Liquid::Token::Variable->new($line, @parts);
98 }
99  
100 29 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
101 # Returns a single token repsending the whole a expression.
102 0 ▶sub parse_expression {
Subroutine parse_expression: not called CC=56 SCAR=80.7
Pod undocumented
103 0 my ($self, $line, $exp) = @_;
104 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
105 0 my @tokens = ();
106 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);
107 # We regex along parentheses, quotation marks (both kinds), whitespace, and non-word-operators.
108 # 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 (=, ==)
109 # There's no confusion, we always try to match the largest first.
110 0 my $non_word_operators = join("|", map { quotemeta($_) } grep { $_ =~ m/^\W+$/; } sort { length($b) <=> length($a) } keys(%{$self->operators}));
111 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
112 0 my ($rs, $re, $rc, $whitespace, $nword_op) = ($-[0], $+[0], $&, $1, $2);
113 # Specifically to allow variables to have a - in them, and be treated as a long literal, instead of a minus sign.
114 # This is terrible behaviour, but mimics Shopify's lexer.
115 # Only if of course the entire first half of this ISN'T a number, though. 'cause that'd be insane.
116 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
117 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
118 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
119 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
120 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
121 # Deal with parentheses; always the highest level of operation, except when inside a square bracket.
122 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
123 0 $start_space = $re;
124 0 push(@tokens, WWW::Shopify::Liquid::Token::Grouping->new($line, $self->parse_expression($line, substr($exp, $start_paren, $rs - $start_paren))));
125 }
126 0 ▶ --$sq_level if $rc eq "]";
Branch: 1 branch
BranchTrueFalseTotal
if $rc eq "]" 0 0 0
127 0 ▶ --$hsh_level if $rc eq "}";
Branch: 1 branch
BranchTrueFalseTotal
if $rc eq "}" 0 0 0
128 0 ▶ die new WWW::Shopify::Liquid::Exception::Lexer::UnbalancedBrace($line) if $hsh_level < 0 || $sq_level < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $hsh_level < 0 or $sq_level < 0 0 0 0
Condition0%0/3
$hsh_level < 0 or $sq_level < 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$hsh_level < 0 or $sq_level < 0
$hsh_level < 0 $sq_level < 0
Truth table0%0/3
A or B
A= $hsh_level < 0B= $sq_level < 0
ABresult
1X1
011
000
129 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
130 # If we're only spaces, that means we're a new a token.
131 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
132 0 ▶ if (defined $start_space) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $start_space) 0 0 0
133 0 my $contents = substr($exp, $start_space, $rs - $start_space);
134 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
135 }
136 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
137 0 $start_space = $re;
138 }
139 }
140 }
141 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
142 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
143 }
144 0 ▶ die WWW::Shopify::Liquid::Exception::Lexer::UnbalancedBrace->new($line) unless $level == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $level == 0 0 0 0
145 # Go through and combine any -1 from OP NUM to NUM.
146 my @ids = grep {
147 0 $tokens[$_]->isa('WWW::Shopify::Liquid::Token::Number') &&
148 0 ▶ $tokens[$_-1]->isa('WWW::Shopify::Liquid::Token::Operator') && $tokens[$_-1]->{core} eq "-" &&
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
149 ($_ == 1 || $tokens[$_-2]->isa('WWW::Shopify::Liquid::Token::Separator') || $tokens[$_-2]->isa('WWW::Shopify::Liquid::Token::Operator'))
150 } 1..$#tokens;
151 0 for (@ids) { $tokens[$_]->{core} *= -1; $tokens[$_-1] = undef; }
152 0 @tokens = grep { defined $_ } @tokens;
153 # Go through and combine colon separated arguments into named arguments.
154 @ids = grep {
155 0 ($_ == 2 || !$tokens[$_-3]->isa('WWW::Shopify::Liquid::Token::Operator') || $tokens[$_-3]->{core} ne "|") &&
156 0 $tokens[$_-2]->isa('WWW::Shopify::Liquid::Token::Variable') && int(@{$tokens[$_-2]->{core}}) == 1 && $tokens[$_-2]->{core}->[0]->isa('WWW::Shopify::Liquid::Token::String') &&
157 0 ▶ $tokens[$_-1]->isa('WWW::Shopify::Liquid::Token::Separator') && $tokens[$_-1]->{core} eq ":" &&
Condition0%0/24
($_ == 2 || !$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 ':' && $tokens[$_]->isa('WWW::Shopify::Liquid::Token::Operand')
!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") 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/9
($_ == 2 || !$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 ':' && $tokens[$_]->isa('WWW::Shopify::Liquid::Token::Operand')
$_ == 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 ":" $tokens[$_]->isa('WWW::Shopify::Liquid::Token::Operand')
Truth table0%0/22
A or not(B) or C and D and E and F and G and H && I
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 ":"I= $tokens[$_]->isa('WWW::Shopify::Liquid::Token::Operand')
ABCDEFGHIresult
000XXXXXX0
1XX0XXXXX0
01X0XXXXX0
0010XXXXX0
1XX10XXXX0
01X10XXXX0
00110XXXX0
1XX110XXX0
01X110XXX0
001110XXX0
1XX1110XX0
01X1110XX0
0011110XX0
1XX11110X0
01X11110X0
00111110X0
1XX1111100
01X1111100
0011111100
1XX1111111
01X1111111
0011111111
158 $tokens[$_]->isa('WWW::Shopify::Liquid::Token::Operand')
159 } (2..$#tokens);
160 0 for (@ids) { $tokens[$_] = WWW::Shopify::Liquid::Token::Variable::Named->new($line, $tokens[$_-2]->{core}->[0]->{core}, $tokens[$_]); $tokens[$_-2] = undef; $tokens[$_-1] = undef; }
161 0 @tokens = grep { defined $_ } @tokens;
162 0 return @tokens;
163 }
164  
165 0 ▶sub parse_text {
Subroutine parse_text: not called CC=40 SCAR=73.5
Pod undocumented
166 0 my ($self, $text) = @_;
167 0 ▶ return () unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 0 0
168 0 my @tokens = ();
169
170 0 my $line = 1;
171 0 my $line_position = 0;
172
173 0 my $lexing_halter;
174 my $open_control_tag;
175 0 my $open_output_tag;
176 0 my $open_single_quote;
177 0 my $open_double_quote;
178 0 my $strip_left;
179
180 0 my $end_offset = 0;
181 0 my $start_position = [1, 0, 0];
182
183 # This is a substitution instead of a simple match, because very long perl native UTF8 strings, are variable length
184 # meaning any substr, or index operations need to walk the string in order to complete. This is like an o(n^2) consequence
185 # so it's fine at smaller lengths, but at larger lengths, it's infeasible to call substr on far offsets with any significant
186 # frequency. So we eat the string as we process it. Possibly slightly slower than simple matching on byte-strings, but way
187 # faster on UTF-8, and at this point in my life, I just want consistency rather than best-possible-performance (this would because
188 # written in D -betterC if I was interested in best possible performance at this point.)
189 0 my $accumulator = '';
190 # Step 1. We only care about new lines (to count what line we're on), {% and {{.
191 0 my $count = 0;
192 29 ▶ use Time::HiRes qw(time);
Subroutine BEGIN: called CC=1 SCAR=0.0
193 0 my $start = time;
194 0 ▶ while ($text =~ s/^(.*?)(?:(\{\{\-?)|({%\-?))//s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ s/^(.*?)(?:(\{\{\-?)|({%\-?))//s) 0 0 0
195 0 $end_offset += $+[0];
196 # These variables are entirely boolean flags.
197 0 my ($start_output_tag, $start_control_tag) = ($2, $3);
198 0 $accumulator .= $1;
199 0 ▶ if ($accumulator ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($accumulator ne "") 0 0 0
200 # Count the number of lines in the accumulator, to ensure we have the approrpiate line position.
201 0 $line += ($accumulator =~ tr/\n//);
202 0 $line_position = rindex($accumulator, "\n") + $start_position->[2] + 1;
203 }
204 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
205 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
206 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
207
208 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
209 0 ▶ $accumulator =~ s/\s*$// if $strip_left;
Branch: 1 branch
BranchTrueFalseTotal
if $strip_left 0 0 0
210 0 ▶ if ($accumulator ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($accumulator ne "") 0 0 0
211 # Count the number of lines in the accumulator.
212 0 push(@tokens, WWW::Shopify::Liquid::Token::Text->new($start_position, $accumulator));
213 0 $accumulator = '';
214 }
215 0 ▶ last if $text eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $text eq "" 0 0 0
216 0 $start_position = [$line, $end_offset - $line_position, $end_offset, $self->file_context];
217
218 # Step 2. If we have an open tag, we parse out tokens from argument context inside that tag.
219 0 ▶ while ($text =~ s/(.*?)(?:(\")|(\')|(\-?%})|(\-?\}\})|(\r?\n))//s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ s/(.*?)(?:(\")|(\')|(\-?%})|(\-?\}\})|(\r?\n))//s) 0 0 0
220 0 my ($double_quote, $single_quote, $end_control_tag, $end_output_tag, $newline) = ($2, $3, $4, $5, $6);
221 0 $end_offset += $+[0];
222
223 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
224 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
225 0 $accumulator .= $1;
226 0 ▶ if ($end_output_tag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($end_output_tag) { } 0 0 0
227 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
228 0 push(@tokens, WWW::Shopify::Liquid::Token::Output->new($open_output_tag, [$self->parse_expression($start_position, $accumulator)], $strip_left, $strip_right));
229 0 $open_output_tag = undef;
230 } else {
231 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
232 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
233 0 push(@tokens, WWW::Shopify::Liquid::Token::Tag->new($open_control_tag, $1, [$self->parse_expression($start_position, $2)], $strip_left, $strip_right));
234 0 ▶ $lexing_halter = $tokens[-1] if $self->{lexing_halters}->{$1};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"lexing_halters"}{$1} 0 0 0
235 0 $open_control_tag = undef;
236 }
237 0 $accumulator = '';
238 0 $start_position = [$line, $end_offset - $line_position, $end_offset, $self->file_context];
239 0 last;
240 } else {
241 0 ▶ if ($newline) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newline) 0 0 0
242 0 ++$line;
243 0 $line_position = $end_offset;
244 }
245 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
246 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
247 0 $accumulator .= $&;
248 }
249 }
250 # For lexing halters, consume everything up to the next end tag explicitly.
251 0 ▶ if ($lexing_halter) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lexing_halter) 0 0 0
252 0 my $core = $lexing_halter->{tag};
253 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
254 0 ▶ if ($3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($3) { } 0 0 0
255 0 ++$line;
256 0 $line_position = $end_offset;
257 0 $accumulator .= $1 . $3;
258 } else {
259 0 $accumulator .= $1;
260 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
261 0 push(@tokens, WWW::Shopify::Liquid::Token::Tag->new($start_position, "end$core", []));
262 0 $accumulator = '';
263 0 $lexing_halter = undef;
264 0 last;
265 }
266 }
267 }
268 }
269 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
270 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
271 0 ▶ die new WWW::Shopify::Liquid::Exception::Lexer::UnbalancedLexingHalt($lexing_halter) if $lexing_halter;
Branch: 1 branch
BranchTrueFalseTotal
if $lexing_halter 0 0 0
272 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
273 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
274 0 $accumulator .= $text;
275 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
276 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
277 0 return @tokens;
278 }
279  
280 0 ▶sub unparse_token {
Subroutine unparse_token: not called CC=13 SCAR=52.0
Pod undocumented
281 0 my ($self, $token) = @_;
282 0 ▶ return "null" if !defined $token;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $token 0 0 0
283 0 ▶ return '' if $token eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $token eq "" 0 0 0
284 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
285 0 ▶ return $token unless blessed($token);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($token) 0 0 0
286 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
287 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
288 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
289 0 ▶ sub translate_variable {
Subroutine translate_variable: not called CC=4 SCAR=30.0
Pod undocumented
290 0 my ($self, $token) = @_;
291 my $variable = join(".", map {
292 !$self->is_processed($_) ? (
293 $_->isa('WWW::Shopify::Liquid::Token::Variable') ? ('[' . translate_variable($self, $_) . ']') :
294 ($_->isa('WWW::Shopify::Liquid::Token::Variable::Processing') ? $_->{core}->name : $_->{core})
295 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
296 0 } @{$token->{core}});
297 0 $variable =~ s/\.\[/\[/g;
298 0 return $variable;
299 }
300 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
301 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
302 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
303 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
304 0 return $token->{core};
305 }
306  
307 0 ▶sub unparse_expression {
Subroutine unparse_expression: not called CC=3 SCAR=24.8
Pod undocumented
308 0 my ($self, @tokens) = @_;
309 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
310 0 $a =~ s/^ //;
311 0 return $a;
312 }
313  
314 0 ▶sub unparse_text_segment {
Subroutine unparse_text_segment: not called CC=7 SCAR=40.3
Pod undocumented
315 0 my ($self, $token) = @_;
316 0 ▶ my $space = $self->unparse_spaces ? " " : "";
Branch: 1 branch
BranchTrueFalseTotal
$self->unparse_spaces ? : 0 0 0
317 0 ▶ return $token if $self->is_processed($token);
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_processed($token) 0 0 0
318 0 ▶ if ($token->isa('WWW::Shopify::Liquid::Token::Tag')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->isa("WWW::Shopify::Liquid::Token::Tag")) 0 0 0
319 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
320 0 return "{%" . $space . $token->{tag} . " " . $self->unparse_expression(@{$token->{arguments}}) . $space . "%}";
321 }
322 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
323 0 return $token->{core};
324 }
325  
326 0 ▶sub unparse_text {
Subroutine unparse_text: not called CC=1 SCAR=6.9
Pod undocumented
327 0 my ($self, @tokens) = @_;
328 0 return join('', grep { defined $_ } map { $self->unparse_text_segment($_) } @tokens);
329 }
330  
331 29 1;
↑ Summary lib/WWW/Shopify/Liquid/Tag/Assign.pm »