lib/WWW/Shopify/Liquid/Tag/Assign.pm

filter: Statementstmt 25.0% 16 / 64 Branchbran 0.0% 0 / 54 Conditioncond 0.0% 0 / 39 MC/DCmcdc 0.0% 0 / 20 Subroutinesub 55.5% 5 / 9 Podpod 0.0% 0 / 4 totaltotal 11.0% 21 / 190 CC 44 SCAR 72.9
CC
44
Cov
10%
process
1806.0
verify
12.0
min_arguments
2.0
CRAP 1459.6
« lib/WWW/Shopify/Liquid/Lexer.pm ↑ Summary lib/WWW/Shopify/Liquid/Parser.pm »
1 #!/usr/bin/perl
2 38 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 38 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 38 ▶use WWW::Shopify::Liquid::Tag;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 package WWW::Shopify::Liquid::Tag::Assign;
8 38 ▶use base 'WWW::Shopify::Liquid::Tag::Free';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 38 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 0 ▶sub min_arguments { return 1; }
Subroutine min_arguments: not called CC=1 SCAR=6.9
Pod undocumented
11 0 ▶sub max_arguments { return 1; }
Subroutine max_arguments: not called CC=1 SCAR=6.9
Pod undocumented
12 0 ▶sub verify {
Subroutine verify: not called CC=3 SCAR=24.8
Pod undocumented
13 0 my ($self) = @_;
14 die new WWW::Shopify::Liquid::Exception::Parser::Arguments($self, "Requires assignment operator to be the first thing in an assign tag.") unless
15 0 ▶ $self->{arguments}->[0]->isa('WWW::Shopify::Liquid::Operator::Assignment');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"arguments"}[0]->isa("WWW::Shopify::Liquid::Operator::Assignment") 0 0 0
16 die new WWW::Shopify::Liquid::Exception::Parser::Arguments($self, "Requires a literal referring to a variable for what you're assigning to.") unless
17 0 ▶ $self->{arguments}->[0]->{operands}->[0]->isa('WWW::Shopify::Liquid::Token::Variable');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"arguments"}[0]{"operands"}[0]->isa("WWW::Shopify::Liquid::Token::Variable") 0 0 0
18 }
19 0 ▶sub process {
Subroutine process: not called CC=42 SCAR=75.0
Pod undocumented
20 0 my ($self, $hash, $action, $pipeline) = @_;
21 0 ▶ my @vars = map { $self->is_processed($_) ? $_ : $_->$action($pipeline, $hash) } @{$self->{arguments}->[0]->{operands}->[0]->{core}};
Branch: 1 branch
BranchTrueFalseTotal
$self->is_processed($_) ? : 0 0 0
22 0 ▶ return $self if $action eq "optimize" && int(grep { !$self->is_processed($_) } @vars) > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $action eq "optimize" and int grep({not $self->is_processed($_);} @vars) > 0 0 0 0
Condition0%0/3
$action eq "optimize" and int grep({not $self->is_processed($_);} @vars) > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$action eq "optimize" and int grep({not $self->is_processed($_);} @vars) > 0
$action eq "optimize" int grep({not $self->is_processed($_);} @vars) > 0
Truth table0%0/3
A and B
A= $action eq "optimize"B= int grep({not $self->is_processed($_);} @vars) > 0
ABresult
0X0
100
111
23
24
25 0 my $inner_hash = $hash;
26 0 for (0..$#vars-1) {
27 0 ▶ return $self if ref($inner_hash) && ref($inner_hash) eq "HASH" && !exists $inner_hash->{$vars[$_]} && $action eq 'optimize';
Branch: 1 branch
BranchTrueFalseTotal
if ref $inner_hash and ref $inner_hash eq "HASH" and not exists $$inner_hash{$vars[$_]} and $action eq "optimize" 0 0 0
Condition0%0/9
ref $inner_hash and ref $inner_hash eq "HASH" and not exists $$inner_hash{$vars[$_]} and $action eq "optimize"
!ll&&!rl&&r
000
ref $inner_hash and ref $inner_hash eq "HASH" and not exists $$inner_hash{$vars[$_]}
!ll&&!rl&&r
000
ref $inner_hash and ref $inner_hash eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/4
ref $inner_hash and ref $inner_hash eq "HASH" and not exists $$inner_hash{$vars[$_]} and $action eq "optimize"
ref $inner_hash ref $inner_hash eq "HASH" not exists $$inner_hash{$vars[$_]} $action eq "optimize"
Truth table0%0/5
A and B and not(C) and D
A= ref $inner_hashB= ref $inner_hash eq "HASH"C= not exists $$inner_hash{$vars[$_]}D= $action eq "optimize"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
28 0 ▶ if (looks_like_number($vars[$_]) && ref($inner_hash) && ref($inner_hash) eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (&looks_like_number($vars[$_]) and ref $inner_hash and ref $inner_hash eq 'ARRAY') { } 0 0 0
Condition0%0/6
&looks_like_number($vars[$_]) and ref $inner_hash and ref $inner_hash eq "ARRAY"
!ll&&!rl&&r
000
&looks_like_number($vars[$_]) and ref $inner_hash
!ll&&!rl&&r
000
MC/DC0%0/3
&looks_like_number($vars[$_]) and ref $inner_hash and ref $inner_hash eq "ARRAY"
&looks_like_number($vars[$_]) ref $inner_hash ref $inner_hash eq "ARRAY"
Truth table0%0/4
A and B and C
A= &looks_like_number($vars[$_])B= ref $inner_hashC= ref $inner_hash eq "ARRAY"
ABCresult
0XX0
10X0
1100
1111
29 0 ▶ $inner_hash->[$vars[$_]] = {} if !defined $inner_hash->[$vars[$_]];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$inner_hash[$vars[$_]] 0 0 0
30 0 $inner_hash = $inner_hash->[$vars[$_]];
31 } else {
32 0 ▶ $inner_hash->{$vars[$_]} = {} if !exists $inner_hash->{$vars[$_]};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$inner_hash{$vars[$_]} 0 0 0
33 0 $inner_hash = $inner_hash->{$vars[$_]};
34 }
35 }
36
37
38 0 my $result = $self->{arguments}->[0]->{operands}->[1];
39 # For now, only do renders.
40 0 ▶ if ($action eq "optimize") {
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq 'optimize') { } 0 0 0
41 0 ▶ if (exists $inner_hash->{$vars[-1]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$inner_hash{$vars[-1]}) { } 0 0 0
42 0 my $value = delete $inner_hash->{$vars[-1]};
43 0 ▶ $result = $result->$action($pipeline, $hash) if !$self->is_processed($result);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_processed($result) 0 0 0
44 0 ▶ $inner_hash->{$vars[-1]} = $result if $self->is_processed($result);
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_processed($result) 0 0 0
45 } else {
46 0 ▶ $result = $result->$action($pipeline, $hash) if !$self->is_processed($result);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_processed($result) 0 0 0
47 }
48 0 ▶ $self->{arguments}->[0]->{operands}->[1] = $result if $self->is_processed($result);
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_processed($result) 0 0 0
49 # If we run across something that should be assigned, we must delete it in the hash to preserve uncertainty.
50 # OK, no. We still return ourselves, but we do a bit of a deeper analysis. If the assignment is out the in the open, we assign.
51 # If the assignment is contingent upon a conditional, (i.e. inside something that isn't fully resolved). Then we delete it.
52 0 $pipeline->flag_conditional_uncertainty(\@vars);
53 0 ▶ $inner_hash->{$vars[-1]} = $result if $self->is_processed($result);
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_processed($result) 0 0 0
54 0 ▶ return undef if $pipeline->remove_assignment && !defined $pipeline->conditional_state;
Branch: 1 branch
BranchTrueFalseTotal
if $pipeline->remove_assignment and not defined $pipeline->conditional_state 0 0 0
Condition0%0/3
$pipeline->remove_assignment and not defined $pipeline->conditional_state
!ll&&!rl&&r
000
MC/DC0%0/2
$pipeline->remove_assignment and not defined $pipeline->conditional_state
$pipeline->remove_assignment not defined $pipeline->conditional_state
Truth table0%0/3
A and not(B)
A= $pipeline->remove_assignmentB= not defined $pipeline->conditional_state
ABresult
0X0
100
111
55 0 return $self;
56 } else {
57 0 ▶ $result = $result->$action($pipeline, $hash) if !$self->is_processed($result);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_processed($result) 0 0 0
58 }
59 0 ▶ return $self unless $self->is_processed($result);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_processed($result) 0 0 0
60
61 0 my $assignment = $self->{arguments}->[0];
62 0 ▶ if (looks_like_number($vars[-1]) && ref($inner_hash) && ref($inner_hash) eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (&looks_like_number($vars[-1]) and ref $inner_hash and ref $inner_hash eq 'ARRAY') { } 0 0 0
Condition0%0/6
&looks_like_number($vars[-1]) and ref $inner_hash and ref $inner_hash eq "ARRAY"
!ll&&!rl&&r
000
&looks_like_number($vars[-1]) and ref $inner_hash
!ll&&!rl&&r
000
MC/DC0%0/3
&looks_like_number($vars[-1]) and ref $inner_hash and ref $inner_hash eq "ARRAY"
&looks_like_number($vars[-1]) ref $inner_hash ref $inner_hash eq "ARRAY"
Truth table0%0/4
A and B and C
A= &looks_like_number($vars[-1])B= ref $inner_hashC= ref $inner_hash eq "ARRAY"
ABCresult
0XX0
10X0
1100
1111
63 0 ▶ if ($assignment->isa('WWW::Shopify::Liquid::Operator::PlusAssignment')) {
Branch: 4 branches
BranchTrueFalseTotal
if ($assignment->isa('WWW::Shopify::Liquid::Operator::PlusAssignment')) { } 0 0 0
elsif ($assignment->isa('WWW::Shopify::Liquid::Operator::MinusAssignment')) { } 0 0 0
elsif ($assignment->isa('WWW::Shopify::Liquid::Operator::MultiplyAssignment')) { } 0 0 0
elsif ($assignment->isa('WWW::Shopify::Liquid::Operator::DivideAssignment')) { } 0 0 0
64 0 ▶ $inner_hash->[$vars[-1]] += ($result || 0);
Condition0%0/2
$result || 0
l!l
00
MC/DC0%0/1
$result || 0
$result
Truth table0%0/2
A
A= $result
Aresult
11
00
65 } elsif ($assignment->isa('WWW::Shopify::Liquid::Operator::MinusAssignment')) {
66 0 ▶ $inner_hash->[$vars[-1]] -= ($result || 0);
Condition0%0/2
$result || 0
l!l
00
MC/DC0%0/1
$result || 0
$result
Truth table0%0/2
A
A= $result
Aresult
11
00
67 } elsif ($assignment->isa('WWW::Shopify::Liquid::Operator::MultiplyAssignment')) {
68 0 ▶ $inner_hash->[$vars[-1]] *= ($result || 0);
Condition0%0/2
$result || 0
l!l
00
MC/DC0%0/1
$result || 0
$result
Truth table0%0/2
A
A= $result
Aresult
11
00
69 } elsif ($assignment->isa('WWW::Shopify::Liquid::Operator::DivideAssignment')) {
70 0 $inner_hash->[$vars[-1]] /= $result;
71 } else {
72 0 $inner_hash->[$vars[-1]] = $result;
73 }
74 } else {
75 0 ▶ if ($assignment->isa('WWW::Shopify::Liquid::Operator::PlusAssignment')) {
Branch: 4 branches
BranchTrueFalseTotal
if ($assignment->isa('WWW::Shopify::Liquid::Operator::PlusAssignment')) { } 0 0 0
elsif ($assignment->isa('WWW::Shopify::Liquid::Operator::MinusAssignment')) { } 0 0 0
elsif ($assignment->isa('WWW::Shopify::Liquid::Operator::MultiplyAssignment')) { } 0 0 0
elsif ($assignment->isa('WWW::Shopify::Liquid::Operator::DivideAssignment')) { } 0 0 0
76 0 ▶ $inner_hash->{$vars[-1]} += ($result || 0);
Condition0%0/2
$result || 0
l!l
00
MC/DC0%0/1
$result || 0
$result
Truth table0%0/2
A
A= $result
Aresult
11
00
77 } elsif ($assignment->isa('WWW::Shopify::Liquid::Operator::MinusAssignment')) {
78 0 ▶ $inner_hash->{$vars[-1]} -= ($result || 0);
Condition0%0/2
$result || 0
l!l
00
MC/DC0%0/1
$result || 0
$result
Truth table0%0/2
A
A= $result
Aresult
11
00
79 } elsif ($assignment->isa('WWW::Shopify::Liquid::Operator::MultiplyAssignment')) {
80 0 ▶ $inner_hash->{$vars[-1]} *= ($result || 0);
Condition0%0/2
$result || 0
l!l
00
MC/DC0%0/1
$result || 0
$result
Truth table0%0/2
A
A= $result
Aresult
11
00
81 } elsif ($assignment->isa('WWW::Shopify::Liquid::Operator::DivideAssignment')) {
82 0 $inner_hash->{$vars[-1]} /= $result;
83 } else {
84 0 $inner_hash->{$vars[-1]} = $result;
85 }
86 }
87 0 return '';
88 }
89  
90  
91  
92 38 1;
« lib/WWW/Shopify/Liquid/Lexer.pm ↑ Summary lib/WWW/Shopify/Liquid/Parser.pm »