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

filter: Statementstmt 17.3% 13 / 75 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 24 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 36.3% 4 / 11 Podpod 0.0% 0 / 7 totaltotal 10.4% 17 / 162 CC 26 SCAR 42.4
CC
26
Cov
10%
retrieve_include
132.0
process
90.0
include_literal
30.0
CRAP 69.5
« lib/WWW/Shopify/Liquid/Tag/CreateTag.pm ↑ Summary lib/WWW/Shopify/Liquid/Tag/Case.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::Include;
6 38 ▶use base 'WWW::Shopify::Liquid::Tag::Free';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 38 ▶use File::Slurp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 0 ▶sub max_arguments { return 1; }
Subroutine max_arguments: not called CC=1 SCAR=6.9
Pod undocumented
10 0 ▶sub min_arguments { return 1; }
Subroutine min_arguments: not called CC=1 SCAR=6.9
Pod undocumented
11  
12 0 ▶sub verify {
Subroutine verify: not called CC=1 SCAR=6.9
Pod undocumented
13 0 my ($self) = @_;
14 }
15  
16 0 ▶sub retrieve_include {
Subroutine retrieve_include: not called CC=11 SCAR=48.8
Pod undocumented
17 0 my ($self, $hash, $action, $pipeline, $string) = @_;
18 0 ▶ if ($pipeline->inclusion_context && $pipeline->parent) {
Branch: 2 branches
BranchTrueFalseTotal
if ($pipeline->inclusion_context and $pipeline->parent) { } 0 0 0
elsif ($action eq 'render') { } 0 0 0
Condition0%0/3
$pipeline->inclusion_context and $pipeline->parent
!ll&&!rl&&r
000
MC/DC0%0/2
$pipeline->inclusion_context and $pipeline->parent
$pipeline->inclusion_context $pipeline->parent
Truth table0%0/3
A and B
A= $pipeline->inclusion_contextB= $pipeline->parent
ABresult
0X0
100
111
19 # Inclusion contexts are evaluated from left to right, in order of priority.
20 0 ▶ my @inclusion_contexts = $pipeline->inclusion_context && ref($pipeline->inclusion_context) && ref($pipeline->inclusion_context) eq "ARRAY" ? @{$pipeline->inclusion_context} : $pipeline->inclusion_context;
Branch: 1 branch
BranchTrueFalseTotal
$pipeline->inclusion_context && ref $pipeline->inclusion_context && ref $pipeline->inclusion_context eq 'ARRAY' ? : 0 0 0
Condition0%0/6
$pipeline->inclusion_context and ref $pipeline->inclusion_context and ref $pipeline->inclusion_context eq "ARRAY"
!ll&&!rl&&r
000
$pipeline->inclusion_context and ref $pipeline->inclusion_context
!ll&&!rl&&r
000
MC/DC0%0/3
$pipeline->inclusion_context and ref $pipeline->inclusion_context and ref $pipeline->inclusion_context eq "ARRAY"
$pipeline->inclusion_context ref $pipeline->inclusion_context ref $pipeline->inclusion_context eq "ARRAY"
Truth table0%0/4
A and B and C
A= $pipeline->inclusion_contextB= ref $pipeline->inclusion_contextC= ref $pipeline->inclusion_context eq "ARRAY"
ABCresult
0XX0
10X0
1100
1111
21 0 ▶ die new WWW::Shopify::Liquid::Exception([], "Backtracking not allowed in inclusions.") if $string =~ m/\.\./;
Branch: 1 branch
BranchTrueFalseTotal
if $string =~ /\.\./ 0 0 0
22 0 for (@inclusion_contexts) {
23 0 ▶ if (ref($_) eq "CODE") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_ eq 'CODE') { } 0 0 0
24 0 return $_->($self, $hash, $action, $pipeline, $string);
25 } else {
26 0 my $path = $_ . "/" . $string . ".liquid";
27 0 ▶ return ($path, scalar(read_file($path))) if -e $path;
Branch: 1 branch
BranchTrueFalseTotal
if -e $path 0 0 0
28 }
29 }
30 0 die new WWW::Shopify::Liquid::Exception([], "Can't find include $string.");
31 } elsif ($action eq "render") {
32 0 die new WWW::Shopify::Liquid::Exception::Renderer::Unimplemented($self);
33 }
34 0 return $self;
35 }
36  
37 0 ▶sub include_literal {
Subroutine include_literal: not called CC=5 SCAR=34.0
Pod undocumented
38 0 my ($self) = @_;
39 0 my $literal = $self->{arguments}->[0];
40 0 ▶ if ($literal && ref($literal) && $literal->isa('WWW::Shopify::Liquid::Operator::With')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($literal and ref $literal and $literal->isa('WWW::Shopify::Liquid::Operator::With')) { } 0 0 0
Condition0%0/6
$literal and ref $literal and $literal->isa("WWW::Shopify::Liquid::Operator::With")
!ll&&!rl&&r
000
$literal and ref $literal
!ll&&!rl&&r
000
MC/DC0%0/3
$literal and ref $literal and $literal->isa("WWW::Shopify::Liquid::Operator::With")
$literal ref $literal $literal->isa("WWW::Shopify::Liquid::Operator::With")
Truth table0%0/4
A and B and C
A= $literalB= ref $literalC= $literal->isa("WWW::Shopify::Liquid::Operator::With")
ABCresult
0XX0
10X0
1100
1111
41 0 $literal = $literal->{arguments}->[0];
42 } else {
43 0 $literal = $literal;
44 }
45 0 ▶ return unless $literal->isa('WWW::Shopify::Liquid::Token::String');
Branch: 1 branch
BranchTrueFalseTotal
unless $literal->isa("WWW::Shopify::Liquid::Token::String") 0 0 0
46 0 return $literal->{core};
47 }
48  
49 0 ▶sub process_include {
Subroutine process_include: not called CC=4 SCAR=30.0
Pod undocumented
50 0 my ($self, $hash, $action, $pipeline, $string, $path, $text, $argument) = @_;
51 0 my $old_context = $pipeline->parent->lexer->file_context;
52 0 $pipeline->parent->lexer->file_context($path);
53 0 $pipeline->parent->parser->file_context($path);
54 0 $pipeline->parent->renderer->file_context($path);
55 # If text is already an AST, then we do not parse the text.
56 0 ▶ my $ast = ref($text) ? $text : $pipeline->parent->parse_text($text);
Branch: 1 branch
BranchTrueFalseTotal
ref $text ? : 0 0 0
57 0 ▶ $hash->{$string} = $argument if defined $argument;
Branch: 1 branch
BranchTrueFalseTotal
if defined $argument 0 0 0
58 0 ▶ if ($action eq "optimize") {
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq 'optimize') { } 0 0 0
59 0 $ast = $pipeline->optimize($hash, $ast);
60 0 $pipeline->parent->lexer->file_context($old_context);
61 0 $pipeline->parent->parser->file_context($old_context);
62 0 $pipeline->parent->renderer->file_context($old_context);
63 0 return $ast;
64 } else {
65 # Perform no hash cloning.
66 0 my $clone_hash = $pipeline->clone_hash;
67 0 $pipeline->clone_hash(0);
68 0 my ($result) = $pipeline->render($hash, $ast);
69 0 $pipeline->clone_hash($clone_hash);
70 0 $pipeline->parent->lexer->file_context($old_context);
71 0 $pipeline->parent->parser->file_context($old_context);
72 0 $pipeline->parent->renderer->file_context($old_context);
73 0 return $result;
74 }
75 }
76  
77 0 ▶sub process {
Subroutine process: not called CC=9 SCAR=45.0
Pod undocumented
78 0 my ($self, $hash, $action, $pipeline) = @_;
79 0 ▶ die new WWW::Shopify::Liquid::Exception([], "Recursive inclusion probable, greater than depth " . $pipeline->max_inclusion_depth . ". Aborting.")
Branch: 1 branch
BranchTrueFalseTotal
if $pipeline->inclusion_depth > $pipeline->max_inclusion_depth 0 0 0
80 if $pipeline->inclusion_depth > $pipeline->max_inclusion_depth;
81 0 ▶ return '' unless int(@{$self->{arguments}}) > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless int @{$self->{"arguments"};} > 0 0 0 0
82 0 my $result = $self->{arguments}->[0]->$action($pipeline, $hash);
83 0 my ($string, $argument);
84 0 ▶ if ($result && ref($result) && $result->isa('WWW::Shopify::Liquid::Operator::With')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result and ref $result and $result->isa('WWW::Shopify::Liquid::Operator::With')) { } 0 0 0
Condition0%0/6
$result and ref $result and $result->isa("WWW::Shopify::Liquid::Operator::With")
!ll&&!rl&&r
000
$result and ref $result
!ll&&!rl&&r
000
MC/DC0%0/3
$result and ref $result and $result->isa("WWW::Shopify::Liquid::Operator::With")
$result ref $result $result->isa("WWW::Shopify::Liquid::Operator::With")
Truth table0%0/4
A and B and C
A= $resultB= ref $resultC= $result->isa("WWW::Shopify::Liquid::Operator::With")
ABCresult
0XX0
10X0
1100
1111
85 0 $string = $result->{operands}->[0]->$action($pipeline, $hash);
86 0 $argument = $result->{operands}->[1]->$action($pipeline, $hash);
87 } else {
88 0 $string = $result;
89 }
90 0 ▶ return $self if !$self->is_processed($string) || !$self->is_processed($argument);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_processed($string) and $self->is_processed($argument) 0 0 0
Condition0%0/3
$self->is_processed($string) and $self->is_processed($argument)
!ll&&!rl&&r
000
MC/DC0%0/2
$self->is_processed($string) and $self->is_processed($argument)
$self->is_processed($string) $self->is_processed($argument)
Truth table0%0/3
A and B
A= $self->is_processed($string)B= $self->is_processed($argument)
ABresult
0X0
100
111
91 0 my ($path, $text) = $self->retrieve_include($hash, $action, $pipeline, $string, $argument);
92 0 ▶ return $self if !$self->is_processed($path);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_processed($path) 0 0 0
93 0 my $include_depth = $pipeline->inclusion_depth;
94 0 $pipeline->inclusion_depth($include_depth+1);
95 0 $result = $self->process_include($hash, $action, $pipeline, $string, $path, $text, $argument);
96 0 $pipeline->inclusion_depth($include_depth);
97 0 return $result;
98
99 }
100  
101  
102  
103 38 1;
« lib/WWW/Shopify/Liquid/Tag/CreateTag.pm ↑ Summary lib/WWW/Shopify/Liquid/Tag/Case.pm »