blib/lib/WWW/Shopify/Liquid/Tag/For.pm

filter: Statementstmt 16.6% 19 / 114 Branchbran 0.0% 0 / 72 Conditioncond 0.0% 0 / 63 MC/DCmcdc 0.0% 0 / 34 Subroutinesub 37.5% 6 / 16 Podpod 0.0% 0 / 10 totaltotal 8.0% 25 / 309 CC 59 SCAR 57.1
CC
59
Cov
8%
process
702.0
render_loop
156.0
optimize_loop
156.0
CRAP 303.4
« blib/lib/WWW/Shopify/Liquid/Tag/Capture.pm ↑ Summary blib/lib/WWW/Shopify/Liquid/Operator/Concatenate.pm »
1 #!/usr/bin/perl
2 30 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 30 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package WWW::Shopify::Liquid::Tag::For;
6 30 ▶use base 'WWW::Shopify::Liquid::Tag::Enclosing';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 0 ▶sub min_arguments { return 1; }
Subroutine min_arguments: not called CC=1 SCAR=6.9
Pod undocumented
9 0 ▶sub max_arguments { return 1; }
Subroutine max_arguments: not called CC=1 SCAR=6.9
Pod undocumented
10  
11 sub verify {
12 0 ▶ my ($self) = @_;
Subroutine verify: not called CC=6 SCAR=37.4
Pod undocumented
13 die new WWW::Shopify::Liquid::Exception::Parser::Arguments($self, "Requires in operator to be part of loop.") unless
14 0 ▶ $self->{arguments}->[0]->isa('WWW::Shopify::Liquid::Operator::In');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"arguments"}[0]->isa("WWW::Shopify::Liquid::Operator::In") 0 0 0
15 die new WWW::Shopify::Liquid::Exception::Parser::Arguments($self, "Requires the opening variable of a loop to be a simple variable.") unless
16 $self->{arguments}->[0]->{operands}->[0] && $self->{arguments}->[0]->{operands}->[0]->isa('WWW::Shopify::Liquid::Token::Variable') &&
17 0 ▶ int(@{$self->{arguments}->[0]->{operands}->[0]->{core}}) == 1 && $self->{arguments}->[0]->{operands}->[0]->{core}->[0]->isa('WWW::Shopify::Liquid::Token::String');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"arguments"}[0]{"operands"}[0] and $self->{"arguments"}[0]{"operands"}[0]->isa("WWW::Shopify::Liquid::Token::Variable") and int @{$self->{"arguments"}[0]{"operands"}[0]{"core"};} == 1 and $self->{"arguments"}[0]{"operands"}[0]{"core"}[0]->isa("WWW::Shopify::Liquid::Token::String") 0 0 0
Condition0%0/9
$self->{"arguments"}[0]{"operands"}[0] and $self->{"arguments"}[0]{"operands"}[0]->isa("WWW::Shopify::Liquid::Token::Variable") and int @{$self->{"arguments"}[0]{"operands"}[0]{"core"};} == 1 and $self->{"arguments"}[0]{"operands"}[0]{"core"}[0]->isa("WWW::Shopify::Liquid::Token::String")
!ll&&!rl&&r
000
$self->{"arguments"}[0]{"operands"}[0] and $self->{"arguments"}[0]{"operands"}[0]->isa("WWW::Shopify::Liquid::Token::Variable") and int @{$self->{"arguments"}[0]{"operands"}[0]{"core"};} == 1
!ll&&!rl&&r
000
$self->{"arguments"}[0]{"operands"}[0] and $self->{"arguments"}[0]{"operands"}[0]->isa("WWW::Shopify::Liquid::Token::Variable")
!ll&&!rl&&r
000
MC/DC0%0/4
$self->{"arguments"}[0]{"operands"}[0] and $self->{"arguments"}[0]{"operands"}[0]->isa("WWW::Shopify::Liquid::Token::Variable") and int @{$self->{"arguments"}[0]{"operands"}[0]{"core"};} == 1 and $self->{"arguments"}[0]{"operands"}[0]{"core"}[0]->isa("WWW::Shopify::Liquid::Token::String")
$self->{"arguments"}[0]{"operands"}[0] $self->{"arguments"}[0]{"operands"}[0]->isa("WWW::Shopify::Liquid::Token::Variable") int @{$self->{"arguments"}[0]{"operands"}[0]{"core"};} == 1 $self->{"arguments"}[0]{"operands"}[0]{"core"}[0]->isa("WWW::Shopify::Liquid::Token::String")
Truth table0%0/5
A and B and C and D
A= $self->{"arguments"}[0]{"operands"}[0]B= $self->{"arguments"}[0]{"operands"}[0]->isa("WWW::Shopify::Liquid::Token::Variable")C= int @{$self->{"arguments"}[0]{"operands"}[0]{"core"};} == 1D= $self->{"arguments"}[0]{"operands"}[0]{"core"}[0]->isa("WWW::Shopify::Liquid::Token::String")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
18 }
19 0 ▶sub inner_tags { return qw(else) }
Subroutine inner_tags: not called CC=1 SCAR=6.9
Pod undocumented
20  
21 30 ▶use List::Util qw(min);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 30 ▶use Scalar::Util qw(looks_like_number blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
23 30 ▶use Clone qw(clone);
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25  
26  
27 sub new {
28 0 ▶ my $package = shift;
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
29 0 my $self = bless {
30 line => shift,
31 core => shift,
32 arguments => shift,
33 contents => undef,
34 false_path => undef
35 }, $package;
36 0 $self->interpret_inner_tokens(@{$_[0]});
37 0 return $self;
38 }
39  
40 sub interpret_inner_tokens {
41 0 ▶ my ($self, @tokens) = @_;
Subroutine interpret_inner_tokens: not called CC=5 SCAR=34.0
Pod undocumented
42 # Comes in [for_path], [tag, other_path]...
43 0 my $token = shift(@tokens);
44 0 ▶ return undef unless $token;
Branch: 1 branch
BranchTrueFalseTotal
unless $token 0 0 0
45 0 $self->{contents} = $token->[0];
46 0 ▶ if (int(@tokens) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (int @tokens > 0) 0 0 0
47 0 ▶ die new WWW::Shopify::Liquid::Exception::Parser($self, "else cannot be anywhere, except the end tag of the for statement.") if int(@tokens) > 1 || $tokens[0]->[0]->tag ne "else";
Branch: 1 branch
BranchTrueFalseTotal
if int @tokens > 1 or $tokens[0][0]->tag ne "else" 0 0 0
Condition0%0/3
int @tokens > 1 or $tokens[0][0]->tag ne "else"
l!l&&r!l&&!r
000
MC/DC0%0/2
int @tokens > 1 or $tokens[0][0]->tag ne "else"
int @tokens > 1 $tokens[0][0]->tag ne "else"
Truth table0%0/3
A or B
A= int @tokens > 1B= $tokens[0][0]->tag ne "else"
ABresult
1X1
011
000
48 0 $self->{false_path} = $tokens[0]->[1];
49 }
50 }
51  
52 sub render_loop {
53 0 ▶ my ($self, $renderer, $hash, $op1, $op2, $start, $end, @array) = @_;
Subroutine render_loop: not called CC=12 SCAR=50.5
Pod undocumented
54
55 0 my @texts = ();
56 0 my $all_processed = 1;
57 0 my $var = $op1->{core}->[0]->{core};
58 0 my $content;
59
60 0 for ($start..$end) {
61 0 $hash->{$var} = $array[$_];
62 $hash->{forloop} = {
63 0 index => ($_+1), index0 => $_, first => $_ == 0, last => $_ == $#array,
64 length => int(@array), rindex0 => (($#array - $_) + 1), rindex => (($#array - $_)),
65 };
66 0 eval {
67 0 $content = $self->{contents}->render($renderer, $hash);
68 };
69 0 ▶ if (my $exp = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $exp = $@) 0 0 0
70 0 ▶ if (defined $exp && blessed($exp) && $exp->isa('WWW::Shopify::Liquid::Exception::Control')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $exp and builtin::blessed($exp) and $exp->isa('WWW::Shopify::Liquid::Exception::Control')) { } 0 0 0
Condition0%0/6
defined $exp and builtin::blessed($exp) and $exp->isa("WWW::Shopify::Liquid::Exception::Control")
!ll&&!rl&&r
000
defined $exp and builtin::blessed($exp)
!ll&&!rl&&r
000
MC/DC0%0/3
defined $exp and builtin::blessed($exp) and $exp->isa("WWW::Shopify::Liquid::Exception::Control")
defined $exp builtin::blessed($exp) $exp->isa("WWW::Shopify::Liquid::Exception::Control")
Truth table0%0/4
A and B and C
A= defined $expB= builtin::blessed($exp)C= $exp->isa("WWW::Shopify::Liquid::Exception::Control")
ABCresult
0XX0
10X0
1100
1111
71 0 ▶ push(@texts, @{$exp->initial_render}) if $exp->initial_render && int(@{$exp->initial_render}) > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $exp->initial_render and int @{$exp->initial_render;} > 0 0 0 0
Condition0%0/3
$exp->initial_render and int @{$exp->initial_render;} > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$exp->initial_render and int @{$exp->initial_render;} > 0
$exp->initial_render int @{$exp->initial_render;} > 0
Truth table0%0/3
A and B
A= $exp->initial_renderB= int @{$exp->initial_render;} > 0
ABresult
0X0
100
111
72 0 ▶ if ($exp->isa('WWW::Shopify::Liquid::Exception::Control::Break')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($exp->isa('WWW::Shopify::Liquid::Exception::Control::Break')) { } 0 0 0
elsif ($exp->isa('WWW::Shopify::Liquid::Exception::Control::Continue')) { } 0 0 0
73 0 last;
74 } elsif ($exp->isa('WWW::Shopify::Liquid::Exception::Control::Continue')) {
75 0 next;
76 }
77 } else {
78 0 die $exp;
79 }
80 }
81 0 ▶ $all_processed = 0 if !$self->is_processed($content);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_processed($content) 0 0 0
82 0 push(@texts, $content);
83 }
84
85 0 ▶ return join('', grep { defined $_ } @texts) if $all_processed;
Branch: 1 branch
BranchTrueFalseTotal
if $all_processed 0 0 0
86 0 return $self;
87 }
88  
89 sub expand_concatenations {
90 0 ▶ my ($self, $result) = @_;
Subroutine expand_concatenations: not called CC=3 SCAR=24.8
Pod undocumented
91 0 ▶ return blessed($result) && $result->isa('WWW::Shopify::Liquid::Operator::Concatenate') ? (map { $self->expand_concatenations($_) } @{$result->{operands}}) : ($result);
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($result) && $result->isa('WWW::Shopify::Liquid::Operator::Concatenate') ? : 0 0 0
Condition0%0/3
builtin::blessed($result) and $result->isa("WWW::Shopify::Liquid::Operator::Concatenate")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($result) and $result->isa("WWW::Shopify::Liquid::Operator::Concatenate")
builtin::blessed($result) $result->isa("WWW::Shopify::Liquid::Operator::Concatenate")
Truth table0%0/3
A and B
A= builtin::blessed($result)B= $result->isa("WWW::Shopify::Liquid::Operator::Concatenate")
ABresult
0X0
100
111
92 }
93  
94 sub optimize_loop {
95 0 ▶ my ($self, $optimizer, $hash, $op1, $op2, $start, $end, @array) = @_;
Subroutine optimize_loop: not called CC=12 SCAR=50.5
Pod undocumented
96
97 # First step, we replace everything by a big concatenate.
98 0 my @texts = ();
99
100 0 my $var = $op1->{core}->[0]->{core};
101 0 ▶ return '' if $start > $end;
Branch: 1 branch
BranchTrueFalseTotal
if $start > $end 0 0 0
102 my @parts = map {
103 0 $hash->{$var} = $array[$_];
104 $hash->{forloop} = {
105 0 index => ($_+1), index0 => $_, first => $_ == 0, last => $_ == $#array,
106 length => int(@array), rindex0 => (($#array - $_) + 1), rindex => (($#array - $_)),
107 };
108 0 my $result;
109 0 eval {
110 0 ▶ $result = $self->is_processed($self->{contents}) ? $self->{contents} : clone($self->{contents})->optimize($optimizer, $hash);
Branch: 1 branch
BranchTrueFalseTotal
$self->is_processed($self->{'contents'}) ? : 0 0 0
111 };
112 0 ▶ if (my $exp = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $exp = $@) 0 0 0
113 0 ▶ if (defined $exp && blessed($exp) && $exp->isa('WWW::Shopify::Liquid::Exception::Control')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $exp and builtin::blessed($exp) and $exp->isa('WWW::Shopify::Liquid::Exception::Control')) { } 0 0 0
Condition0%0/6
defined $exp and builtin::blessed($exp) and $exp->isa("WWW::Shopify::Liquid::Exception::Control")
!ll&&!rl&&r
000
defined $exp and builtin::blessed($exp)
!ll&&!rl&&r
000
MC/DC0%0/3
defined $exp and builtin::blessed($exp) and $exp->isa("WWW::Shopify::Liquid::Exception::Control")
defined $exp builtin::blessed($exp) $exp->isa("WWW::Shopify::Liquid::Exception::Control")
Truth table0%0/4
A and B and C
A= defined $expB= builtin::blessed($exp)C= $exp->isa("WWW::Shopify::Liquid::Exception::Control")
ABCresult
0XX0
10X0
1100
1111
114 0 ▶ push(@texts, @{$exp->initial_render}) if $exp->initial_render && int(@{$exp->initial_render}) > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $exp->initial_render and int @{$exp->initial_render;} > 0 0 0 0
Condition0%0/3
$exp->initial_render and int @{$exp->initial_render;} > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$exp->initial_render and int @{$exp->initial_render;} > 0
$exp->initial_render int @{$exp->initial_render;} > 0
Truth table0%0/3
A and B
A= $exp->initial_renderB= int @{$exp->initial_render;} > 0
ABresult
0X0
100
111
115 0 ▶ if ($exp->isa('WWW::Shopify::Liquid::Exception::Control::Break')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($exp->isa('WWW::Shopify::Liquid::Exception::Control::Break')) { } 0 0 0
elsif ($exp->isa('WWW::Shopify::Liquid::Exception::Control::Continue')) { } 0 0 0
116 0 last;
117 } elsif ($exp->isa('WWW::Shopify::Liquid::Exception::Control::Continue')) {
118 0 next;
119 }
120 } else {
121 0 die $exp;
122 }
123 }
124 0 $self->expand_concatenations($result);
125 } ($start..$end);
126 0 ▶ return $parts[0] if int(@parts) == 1;
Branch: 1 branch
BranchTrueFalseTotal
if int @parts == 1 0 0 0
127 0 return WWW::Shopify::Liquid::Operator::Concatenate->new($self->{line}, "", @parts);
128 }
129  
130 # Should eventually support loop unrolling.
131 sub process {
132 0 ▶ my ($self, $hash, $action, $pipeline) = @_;
Subroutine process: not called CC=26 SCAR=65.5
Pod undocumented
133 0 my @args = @{$self->{arguments}};
134
135
136 0 my ($op1, $op2) = @{$args[0]->{operands}};
137 0 ▶ $op2 = $op2->$action($pipeline, $hash) if !$self->is_processed($op2);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_processed($op2) 0 0 0
138
139 0 ▶ $self->{arguments}->[0]->{operands}->[1] = $op2 if $self->is_processed($op2) && $action eq 'optimize';
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_processed($op2) and $action eq "optimize" 0 0 0
Condition0%0/3
$self->is_processed($op2) and $action eq "optimize"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->is_processed($op2) and $action eq "optimize"
$self->is_processed($op2) $action eq "optimize"
Truth table0%0/3
A and B
A= $self->is_processed($op2)B= $action eq "optimize"
ABresult
0X0
100
111
140 0 ▶ return $self if (!$self->is_processed($op2) && $action eq "optimize");
Branch: 1 branch
BranchTrueFalseTotal
if not $self->is_processed($op2) and $action eq "optimize" 0 0 0
Condition0%0/3
not $self->is_processed($op2) and $action eq "optimize"
!ll&&!rl&&r
000
MC/DC0%0/2
not $self->is_processed($op2) and $action eq "optimize"
not $self->is_processed($op2) $action eq "optimize"
Truth table0%0/3
not(A) and B
A= not $self->is_processed($op2)B= $action eq "optimize"
ABresult
0X0
100
111
141 0 ▶ return '' if (!$self->is_processed($op2) && $action eq "render");
Branch: 1 branch
BranchTrueFalseTotal
if not $self->is_processed($op2) and $action eq "render" 0 0 0
Condition0%0/3
not $self->is_processed($op2) and $action eq "render"
!ll&&!rl&&r
000
MC/DC0%0/2
not $self->is_processed($op2) and $action eq "render"
not $self->is_processed($op2) $action eq "render"
Truth table0%0/3
not(A) and B
A= not $self->is_processed($op2)B= $action eq "render"
ABresult
0X0
100
111
142 0 ▶ $op2 = [keys(%$op2)] if ref($op2) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $op2 eq "HASH" 0 0 0
143 0 ▶ return (defined $self->{false_path} ? $self->{false_path}->$action($pipeline, $hash) : '') if ref($op2) ne "ARRAY" || int(@$op2) == 0;
Branch: 2 branches
BranchTrueFalseTotal
if ref $op2 ne "ARRAY" or int @$op2 == 0 0 0 0
defined $self->{'false_path'} ? : 0 0 0
Condition0%0/3
ref $op2 ne "ARRAY" or int @$op2 == 0
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $op2 ne "ARRAY" or int @$op2 == 0
ref $op2 ne "ARRAY" int @$op2 == 0
Truth table0%0/3
A or B
A= ref $op2 ne "ARRAY"B= int @$op2 == 0
ABresult
1X1
011
000
144 0 ▶ die new WWW::Shopify::Liquid::Exception::Renderer::Arguments($self, "Requires an array in for loop.") unless ref($op2) eq "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
unless ref $op2 eq "ARRAY" 0 0 0
145
146 0 my @array = @$op2;
147 0 my $limit = int(@array);
148 0 my $offset = 0;
149
150
151 0 ▶ my ($limit_arg) = grep { $_->isa('WWW::Shopify::Liquid::Token::Variable::Named') && $_->{name} eq "limit" } @args;
Branch: 1 branch
BranchTrueFalseTotal
$_->isa("WWW::Shopify::Liquid::Token::Variable::Named") and $_->{"name"} eq "limit" 0 0 0
152 0 ▶ my $limit_result = $limit_arg->$action($pipeline, $hash) if $limit_arg;
Branch: 1 branch
BranchTrueFalseTotal
if $limit_arg 0 0 0
153 0 ▶ return $self if !$self->is_processed($limit_result);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_processed($limit_result) 0 0 0
154 0 ▶ $limit = $limit_result->{limit} if $limit_result && ref($limit_result) && ref($limit_result) eq 'HASH' && looks_like_number($limit_result->{limit});
Branch: 1 branch
BranchTrueFalseTotal
if $limit_result and ref $limit_result and ref $limit_result eq "HASH" and &looks_like_number($limit_result->{"limit"}) 0 0 0
Condition0%0/9
$limit_result and ref $limit_result and ref $limit_result eq "HASH" and &looks_like_number($limit_result->{"limit"})
!ll&&!rl&&r
000
$limit_result and ref $limit_result and ref $limit_result eq "HASH"
!ll&&!rl&&r
000
$limit_result and ref $limit_result
!ll&&!rl&&r
000
MC/DC0%0/4
$limit_result and ref $limit_result and ref $limit_result eq "HASH" and &looks_like_number($limit_result->{"limit"})
$limit_result ref $limit_result ref $limit_result eq "HASH" &looks_like_number($limit_result->{"limit"})
Truth table0%0/5
A and B and C and D
A= $limit_resultB= ref $limit_resultC= ref $limit_result eq "HASH"D= &looks_like_number($limit_result->{"limit"})
ABCDresult
0XXX0
10XX0
110X0
11100
11111
155
156
157 0 ▶ my ($offset_arg) = grep { $_->isa('WWW::Shopify::Liquid::Token::Variable::Named') && $_->{name} eq "offset" } @args;
Branch: 1 branch
BranchTrueFalseTotal
$_->isa("WWW::Shopify::Liquid::Token::Variable::Named") and $_->{"name"} eq "offset" 0 0 0
158 0 ▶ my $offset_result = $offset_arg->$action($pipeline, $hash) if $offset_arg;
Branch: 1 branch
BranchTrueFalseTotal
if $offset_arg 0 0 0
159 0 ▶ $offset = $offset_result->{offset} if $offset_result && ref($offset_result) && ref($offset_result) eq 'HASH' && looks_like_number($offset_result->{offset});
Branch: 1 branch
BranchTrueFalseTotal
if $offset_result and ref $offset_result and ref $offset_result eq "HASH" and &looks_like_number($offset_result->{"offset"}) 0 0 0
Condition0%0/9
$offset_result and ref $offset_result and ref $offset_result eq "HASH" and &looks_like_number($offset_result->{"offset"})
!ll&&!rl&&r
000
$offset_result and ref $offset_result and ref $offset_result eq "HASH"
!ll&&!rl&&r
000
$offset_result and ref $offset_result
!ll&&!rl&&r
000
MC/DC0%0/4
$offset_result and ref $offset_result and ref $offset_result eq "HASH" and &looks_like_number($offset_result->{"offset"})
$offset_result ref $offset_result ref $offset_result eq "HASH" &looks_like_number($offset_result->{"offset"})
Truth table0%0/5
A and B and C and D
A= $offset_resultB= ref $offset_resultC= ref $offset_result eq "HASH"D= &looks_like_number($offset_result->{"offset"})
ABCDresult
0XXX0
10XX0
110X0
11100
11111
160
161 0 my $dispatch = $action . "_loop";
162
163 0 return $self->$dispatch($pipeline, $hash, $op1, $op2, $offset, min($#array, $limit+$offset-1), @array);
164 }
165  
166  
167  
168 30 1;
« blib/lib/WWW/Shopify/Liquid/Tag/Capture.pm ↑ Summary blib/lib/WWW/Shopify/Liquid/Operator/Concatenate.pm »