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

filter: Statementstmt 20.0% 13 / 65 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 40.0% 4 / 10 Podpod 0.0% 0 / 6 totaltotal 12.9% 17 / 131 CC 19 SCAR 42.3
CC
19
Cov
12%
retrieve_include
110.0
process
90.0
process_include
6.0
CRAP 69.0
« blib/lib/WWW/Shopify/Liquid.pm ↑ Summary blib/lib/WWW/Shopify/Liquid/Filter/Sort.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::Include;
6 30 ▶use base 'WWW::Shopify::Liquid::Tag::Free';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 30 ▶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 sub verify {
13 0 ▶ my ($self) = @_;
Subroutine verify: not called CC=1 SCAR=6.9
Pod undocumented
14 }
15  
16 sub retrieve_include {
17 0 ▶ my ($self, $hash, $action, $pipeline, $string, $argument) = @_;
Subroutine retrieve_include: not called CC=10 SCAR=47.0
Pod undocumented
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 my $path = $_ . "/" . $string . ".liquid";
24 0 ▶ return ($path, scalar(read_file($path))) if -e $path;
Branch: 1 branch
BranchTrueFalseTotal
if -e $path 0 0 0
25 }
26 0 die new WWW::Shopify::Liquid::Exception([], "Can't find include $string.");
27 } elsif ($action eq "render") {
28 0 die new WWW::Shopify::Liquid::Exception::Renderer::Unimplemented($self);
29 }
30 0 return $self;
31 }
32  
33 sub process_include {
34 0 ▶ my ($self, $hash, $action, $pipeline, $path, $text) = @_;
Subroutine process_include: not called CC=2 SCAR=17.9
Pod undocumented
35 0 my $old_context = $pipeline->parent->lexer->file_context;
36 0 $pipeline->parent->lexer->file_context($path);
37 0 $pipeline->parent->parser->file_context($path);
38 0 $pipeline->parent->renderer->file_context($path);
39 0 my $ast = $pipeline->parent->parse_text($text);
40 0 ▶ if ($action eq "optimize") {
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq 'optimize') { } 0 0 0
41 0 $ast = $pipeline->optimize($hash, $ast);
42 0 $pipeline->parent->lexer->file_context($old_context);
43 0 $pipeline->parent->parser->file_context($old_context);
44 0 $pipeline->parent->renderer->file_context($old_context);
45 0 return $ast;
46 } else {
47 # Perform no hash cloning.
48 0 my $clone_hash = $pipeline->clone_hash;
49 0 $pipeline->clone_hash(0);
50 0 my ($result) = $pipeline->render($hash, $ast);
51 0 $pipeline->clone_hash($clone_hash);
52 0 $pipeline->parent->lexer->file_context($old_context);
53 0 $pipeline->parent->parser->file_context($old_context);
54 0 $pipeline->parent->renderer->file_context($old_context);
55 0 return $result;
56 }
57 }
58  
59 sub process {
60 0 ▶ my ($self, $hash, $action, $pipeline) = @_;
Subroutine process: not called CC=9 SCAR=45.0
Pod undocumented
61 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
62 if $pipeline->inclusion_depth > $pipeline->max_inclusion_depth;
63 0 ▶ return '' unless int(@{$self->{arguments}}) > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless int @{$self->{"arguments"};} > 0 0 0 0
64 0 my $result = $self->{arguments}->[0]->$action($pipeline, $hash);
65 0 my ($string, $argument);
66 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
67 0 $string = $result->{arguments}->[0];
68 0 $argument = $result->{arguments}->[1];
69 } else {
70 0 $string = $result;
71 }
72 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
73 0 my ($path, $text) = $self->retrieve_include($hash, $action, $pipeline, $string, $argument);
74 0 ▶ return $self if !$self->is_processed($path);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_processed($path) 0 0 0
75 0 my $include_depth = $pipeline->inclusion_depth;
76 0 $pipeline->inclusion_depth($include_depth+1);
77 0 $result = $self->process_include($hash, $action, $pipeline, $path, $text);
78 0 $pipeline->inclusion_depth($include_depth);
79 0 return $result;
80
81 }
82  
83  
84  
85 30 1;
« blib/lib/WWW/Shopify/Liquid.pm ↑ Summary blib/lib/WWW/Shopify/Liquid/Filter/Sort.pm »