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

filter: Statementstmt 23.2% 13 / 56 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 24 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 30.7% 4 / 13 Podpod 0.0% 0 / 9 totaltotal 11.9% 17 / 142 CC 23 SCAR 41.3
CC
23
Cov
12%
optimize
110.0
render
90.0
interpret_inner_tokens
42.0
CRAP 62.2
« blib/lib/WWW/Shopify/Liquid/Filter/Sort.pm ↑ Summary blib/lib/WWW/Shopify/Liquid/Tag/Case.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::If;
6 30 ▶use base 'WWW::Shopify::Liquid::Tag::Enclosing';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 30 ▶use List::Util qw(first);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 0 ▶sub min_arguments { return 1; }
Subroutine min_arguments: not called CC=1 SCAR=6.9
Pod undocumented
10 0 ▶sub max_arguments { return 1; }
Subroutine max_arguments: not called CC=1 SCAR=6.9
Pod undocumented
11  
12 sub new {
13 0 ▶ my $package = shift;
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
14 0 my $self = bless {
15 line => shift,
16 core => shift,
17 arguments => shift,
18 true_path => undef,
19 false_path => undef
20 }, $package;
21 0 $self->interpret_inner_tokens(@{$_[0]});
22 0 return $self;
23 }
24 0 ▶sub inner_tags { return qw(elsif else) }
Subroutine inner_tags: not called CC=1 SCAR=6.9
Pod undocumented
25 sub interpret_inner_tokens {
26 0 ▶ my ($self, @tokens) = @_;
Subroutine interpret_inner_tokens: not called CC=6 SCAR=37.4
Pod undocumented
27 # Comes in [true_path], [tag, other_path], [tag, other_path], ...
28 0 my $token = shift(@tokens);
29 0 ▶ return undef unless $token;
Branch: 1 branch
BranchTrueFalseTotal
unless $token 0 0 0
30 0 $self->{true_path} = $token->[0];
31 0 ▶ if (int(@tokens) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (int @tokens > 0) 0 0 0
32 0 ▶ die new WWW::Shopify::Liquid::Exception::Parser($self, "else cannot be anywhere, except the end tag of an if statement.") if $tokens[0]->[0]->tag eq "else" && int(@tokens) > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $tokens[0][0]->tag eq "else" and int @tokens > 1 0 0 0
Condition0%0/3
$tokens[0][0]->tag eq "else" and int @tokens > 1
!ll&&!rl&&r
000
MC/DC0%0/2
$tokens[0][0]->tag eq "else" and int @tokens > 1
$tokens[0][0]->tag eq "else" int @tokens > 1
Truth table0%0/3
A and B
A= $tokens[0][0]->tag eq "else"B= int @tokens > 1
ABresult
0X0
100
111
33 0 ▶ if ($tokens[0]->[0]->tag eq "elsif") {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens[0][0]->tag eq 'elsif') { } 0 0 0
34 0 $token = shift(@tokens);
35 0 my $arguments = $token->[0]->{arguments};
36 0 $self->{false_path} = WWW::Shopify::Liquid::Tag::If->new($token->[0]->{line}, "if", $arguments, [[$token->[1]], @tokens]);
37 }
38 else {
39 0 $self->{false_path} = $tokens[0]->[1];
40 }
41 }
42 }
43  
44 0 ▶sub tokens { return ($_[0], map { $_->tokens } grep { defined $_ } ($_[0]->{true_path}, $_[0]->{false_path}, @{$_[0]->{arguments}})) }
Subroutine tokens: not called CC=1 SCAR=6.9
Pod undocumented
45  
46 sub render {
47 0 ▶ my ($self, $renderer, $hash) = @_;
Subroutine render: not called CC=9 SCAR=45.0
Pod undocumented
48 0 ▶ my $arguments = $self->is_processed($self->{arguments}->[0]) ? $self->{arguments}->[0] : $self->{arguments}->[0]->render($renderer, $hash);
Branch: 1 branch
BranchTrueFalseTotal
$self->is_processed($self->{'arguments'}[0]) ? : 0 0 0
49 0 ▶ my $path = $self->{((!$self->inversion && $arguments) || ($self->inversion && !$arguments)) ? 'true_path' : 'false_path'};
Branch: 1 branch
BranchTrueFalseTotal
!$self->inversion && $arguments || $self->inversion && !$arguments ? : 0 0 0
Condition0%0/9
not $self->inversion and $arguments or $self->inversion and not $arguments
l!l&&r!l&&!r
000
not $self->inversion and $arguments
!ll&&!rl&&r
000
$self->inversion and not $arguments
!ll&&!rl&&r
000
MC/DC0%0/4
not $self->inversion and $arguments or $self->inversion and not $arguments
not $self->inversion $arguments $self->inversion not $arguments
Truth table0%0/7
not(A) and B or C and not(D)
A= not $self->inversionB= $argumentsC= $self->inversionD= not $arguments
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
50 0 ▶ $path = $path->render($renderer, $hash) if $path && !$self->is_processed($path);
Branch: 1 branch
BranchTrueFalseTotal
if $path and not $self->is_processed($path) 0 0 0
Condition0%0/3
$path and not $self->is_processed($path)
!ll&&!rl&&r
000
MC/DC0%0/2
$path and not $self->is_processed($path)
$path not $self->is_processed($path)
Truth table0%0/3
A and not(B)
A= $pathB= not $self->is_processed($path)
ABresult
0X0
100
111
51 0 ▶ return defined $path ? $path : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $path ? : 0 0 0
52 }
53  
54 0 ▶sub inversion { return 0; }
Subroutine inversion: not called CC=1 SCAR=6.9
Pod undocumented
55  
56 sub optimize {
57 0 ▶ my ($self, $optimizer, $hash) = @_;
Subroutine optimize: not called CC=10 SCAR=47.0
Pod undocumented
58 0 ▶ $self->{arguments}->[0] = $self->{arguments}->[0]->optimize($optimizer, $hash) if !$self->is_processed($self->{arguments}->[0]);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_processed($self->{"arguments"}[0]) 0 0 0
59 0 ▶ if ($self->is_processed($self->{arguments}->[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_processed($self->{"arguments"}[0])) 0 0 0
60 0 ▶ my $path = $self->{((!$self->inversion && $self->{arguments}->[0]) || ($self->inversion && !$self->{arguments}->[0])) ? 'true_path' : 'false_path'};
Branch: 1 branch
BranchTrueFalseTotal
!$self->inversion && $self->{'arguments'}[0] || $self->inversion && !$self->{'arguments'}[0] ? : 0 0 0
Condition0%0/9
not $self->inversion and $self->{"arguments"}[0] or $self->inversion and not $self->{"arguments"}[0]
l!l&&r!l&&!r
000
not $self->inversion and $self->{"arguments"}[0]
!ll&&!rl&&r
000
$self->inversion and not $self->{"arguments"}[0]
!ll&&!rl&&r
000
MC/DC0%0/4
not $self->inversion and $self->{"arguments"}[0] or $self->inversion and not $self->{"arguments"}[0]
not $self->inversion $self->{"arguments"}[0] $self->inversion not $self->{"arguments"}[0]
Truth table0%0/7
not(A) and B or C and not(D)
A= not $self->inversionB= $self->{"arguments"}[0]C= $self->inversionD= not $self->{"arguments"}[0]
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
61 0 ▶ return $self->is_processed($path) ? $path : $path->optimize($optimizer, $hash);
Branch: 1 branch
BranchTrueFalseTotal
$self->is_processed($path) ? : 0 0 0
62 }
63 0 ▶ if (!$self->is_processed($self->{false_path})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_processed($self->{"false_path"})) 0 0 0
64 0 $optimizer->push_conditional_state;
65 0 $self->{false_path} = $self->{false_path}->optimize($optimizer, $hash);
66 0 $optimizer->pop_conditional_state($hash);
67 }
68 0 ▶ if (!$self->is_processed($self->{true_path})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_processed($self->{"true_path"})) 0 0 0
69 0 $optimizer->push_conditional_state;
70 0 $self->{true_path} = $self->{true_path}->optimize($optimizer, $hash);
71 0 $optimizer->pop_conditional_state($hash);
72 }
73 0 return $self;
74 }
75  
76 30 1;
« blib/lib/WWW/Shopify/Liquid/Filter/Sort.pm ↑ Summary blib/lib/WWW/Shopify/Liquid/Tag/Case.pm »