| 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
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 | ▶ | if (ref($_) eq "CODE") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/6
$literal and ref $literal and $literal->isa("WWW::Shopify::Liquid::Operator::With")
$literal and ref $literal
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")
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | $hash->{$string} = $argument if defined $argument; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if ($action eq "optimize") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | if $pipeline->inclusion_depth > $pipeline->max_inclusion_depth; | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | return '' unless int(@{$self->{arguments}}) > 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
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")
| |||||||||||||||||||||||||||||||||||||||||||
| 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
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)
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||||||||||||||||