| 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
Condition0%0/3
$pipeline->inclusion_context and $pipeline->parent
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/6
$pipeline->inclusion_context and ref $pipeline->inclusion_context and ref $pipeline->inclusion_context eq "ARRAY"
$pipeline->inclusion_context and ref $pipeline->inclusion_context
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | die new WWW::Shopify::Liquid::Exception([], "Backtracking not allowed in inclusions.") if $string =~ m/\.\./; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | if $pipeline->inclusion_depth > $pipeline->max_inclusion_depth; | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | return '' unless int(@{$self->{arguments}}) > 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/6
$result and ref $result and $result->isa("WWW::Shopify::Liquid::Operator::With")
$result and ref $result
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")
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$self->is_processed($string) and $self->is_processed($argument)
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)
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||||||||||||||||