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

filter: Statementstmt 22.0% 13 / 59 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 30 MC/DCmcdc 0.0% 0 / 16 Subroutinesub 30.7% 4 / 13 Podpod 0.0% 0 / 9 totaltotal 10.6% 17 / 159 CC 27 SCAR 45.6
CC
27
Cov
11%
render
182.0
optimize
110.0
interpret_inner_tokens
42.0
CRAP 95.7
« lib/WWW/Shopify/Liquid/Element.pm ↑ Summary lib/WWW/Shopify/Liquid/Tag/CreateTag.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 package WWW::Shopify::Liquid::Tag::If;
6 38 ▶use base 'WWW::Shopify::Liquid::Tag::Enclosing';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 38 ▶use Scalar::Util qw(blessed);
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 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
13 0 my $package = shift;
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 0 ▶sub subelements { qw(true_path false_path arguments); }
Subroutine subelements: not called CC=1 SCAR=6.9
Pod undocumented
26  
27 0 ▶sub interpret_inner_tokens {
Subroutine interpret_inner_tokens: not called CC=6 SCAR=37.4
Pod undocumented
28 0 my ($self, @tokens) = @_;
29 # Comes in [true_path], [tag, other_path], [tag, other_path], ...
30 0 my $token = shift(@tokens);
31 0 ▶ return undef unless $token;
Branch: 1 branch
BranchTrueFalseTotal
unless $token 0 0 0
32 0 $self->{true_path} = $token->[0];
33 0 ▶ if (int(@tokens) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (int @tokens > 0) 0 0 0
34 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
35 0 ▶ if ($tokens[0]->[0]->tag eq "elsif") {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens[0][0]->tag eq 'elsif') { } 0 0 0
36 0 $token = shift(@tokens);
37 0 my $arguments = $token->[0]->{arguments};
38 0 $self->{false_path} = WWW::Shopify::Liquid::Tag::If->new($token->[0]->{line}, "if", $arguments, [[$token->[1]], @tokens]);
39 }
40 else {
41 0 $self->{false_path} = $tokens[0]->[1];
42 }
43 }
44 }
45  
46 0 ▶sub render {
Subroutine render: not called CC=13 SCAR=52.0
Pod undocumented
47 0 my ($self, $renderer, $hash) = @_;
48 0 ▶ return $renderer->state->value($self) if $renderer->state && $renderer->state->value($self);
Branch: 1 branch
BranchTrueFalseTotal
if $renderer->state and $renderer->state->value($self) 0 0 0
Condition0%0/3
$renderer->state and $renderer->state->value($self)
!ll&&!rl&&r
000
MC/DC0%0/2
$renderer->state and $renderer->state->value($self)
$renderer->state $renderer->state->value($self)
Truth table0%0/3
A and B
A= $renderer->stateB= $renderer->state->value($self)
ABresult
0X0
100
111
49 0 my $arguments = $self->render_subelement($renderer, $hash, $self->{arguments});
50 0 my $result;
51 0 eval {
52 0 ▶ my $path = $self->{((!$self->inversion && $arguments->[0]) || ($self->inversion && !$arguments->[0])) ? 'true_path' : 'false_path'};
Branch: 1 branch
BranchTrueFalseTotal
!$self->inversion && $arguments->[0] || $self->inversion && !$arguments->[0] ? : 0 0 0
Condition0%0/9
not $self->inversion and $arguments->[0] or $self->inversion and not $arguments->[0]
l!l&&r!l&&!r
000
not $self->inversion and $arguments->[0]
!ll&&!rl&&r
000
$self->inversion and not $arguments->[0]
!ll&&!rl&&r
000
MC/DC0%0/4
not $self->inversion and $arguments->[0] or $self->inversion and not $arguments->[0]
not $self->inversion $arguments->[0] $self->inversion not $arguments->[0]
Truth table0%0/7
not(A) and B or C and not(D)
A= not $self->inversionB= $arguments->[0]C= $self->inversionD= not $arguments->[0]
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
53 0 ▶ $result = $path && !$self->is_processed($path) ? $path->render($renderer, $hash) : $path;
Branch: 1 branch
BranchTrueFalseTotal
$path && !$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
54 };
55 0 ▶ if (my $exp = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $exp = $@) 0 0 0
56 0 ▶ $exp->value($self->{arguments}, $arguments) if blessed($exp) && $exp->isa('WWW::Shopify::Liquid::Exception::Control::Pause');
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($exp) and $exp->isa("WWW::Shopify::Liquid::Exception::Control::Pause") 0 0 0
Condition0%0/3
builtin::blessed($exp) and $exp->isa("WWW::Shopify::Liquid::Exception::Control::Pause")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($exp) and $exp->isa("WWW::Shopify::Liquid::Exception::Control::Pause")
builtin::blessed($exp) $exp->isa("WWW::Shopify::Liquid::Exception::Control::Pause")
Truth table0%0/3
A and B
A= builtin::blessed($exp)B= $exp->isa("WWW::Shopify::Liquid::Exception::Control::Pause")
ABresult
0X0
100
111
57 0 die $exp;
58 }
59 0 ▶ return defined $result ? $result : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $result ? : 0 0 0
60 }
61  
62 0 ▶sub inversion { return 0; }
Subroutine inversion: not called CC=1 SCAR=6.9
Pod undocumented
63  
64 0 ▶sub optimize {
Subroutine optimize: not called CC=10 SCAR=47.0
Pod undocumented
65 0 my ($self, $optimizer, $hash) = @_;
66 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
67 0 ▶ if ($self->is_processed($self->{arguments}->[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_processed($self->{"arguments"}[0])) 0 0 0
68 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
69 0 ▶ return $self->is_processed($path) ? $path : $path->optimize($optimizer, $hash);
Branch: 1 branch
BranchTrueFalseTotal
$self->is_processed($path) ? : 0 0 0
70 }
71 0 ▶ if (!$self->is_processed($self->{false_path})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_processed($self->{"false_path"})) 0 0 0
72 0 $optimizer->push_conditional_state;
73 0 $self->{false_path} = $self->{false_path}->optimize($optimizer, $hash);
74 0 $optimizer->pop_conditional_state($hash);
75 }
76 0 ▶ if (!$self->is_processed($self->{true_path})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_processed($self->{"true_path"})) 0 0 0
77 0 $optimizer->push_conditional_state;
78 0 $self->{true_path} = $self->{true_path}->optimize($optimizer, $hash);
79 0 $optimizer->pop_conditional_state($hash);
80 }
81 0 return $self;
82 }
83  
84 38 1;
« lib/WWW/Shopify/Liquid/Element.pm ↑ Summary lib/WWW/Shopify/Liquid/Tag/CreateTag.pm »