| 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::Case; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 30 | ▶ | use base 'WWW::Shopify::Liquid::Tag::Enclosing'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 0 | ▶ | sub min_arguments { return 1; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
min_arguments: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 0 | ▶ | sub max_arguments { return 1; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
max_arguments: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 0 | ▶ | my $package = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 0 | my $self = bless { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | line => shift, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | core => shift, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | arguments => shift, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | paths => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | else => undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | }, $package; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | $self->interpret_inner_tokens(@{$_[0]}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | sub inner_tags { return qw(when else); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inner_tags: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # Used to tell the parser to discard all whitespace tags whilst at the inner tag level. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub inner_ignore_whitespace { return 1; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inner_ignore_whitespace: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 30 | ▶ | use List::Util qw(first); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | sub interpret_inner_tokens { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | my ($self, @tokens) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
interpret_inner_tokens: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # Comes in [], [tag, other_path], [tag, other_path], ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | my $token = shift(@tokens); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | die new WWW::Shopify::Liquid::Exception::Parser($self, "Case statements must start with a when statement.") if int(@$token) > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | for (0..$#tokens) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | $token = $tokens[$_]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | die new WWW::Shopify::Liquid::Exception::Parser($self, "Requires a constant when using a when statement.") if $token->[0]->tag eq "when" && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | (!$token->[0]->{arguments}->[0] || ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | ref($token->[0]->{arguments}->[0]) ne "WWW::Shopify::Liquid::Token::String" && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | ref($token->[0]->{arguments}->[0]) ne "WWW::Shopify::Liquid::Token::Number") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$token->[0]->tag eq "when" and !$token->[0]{"arguments"}[0] || ref $token->[0]{"arguments"}[0] ne "WWW::Shopify::Liquid::Token::String" && ref $token->[0]{"arguments"}[0] ne "WWW::Shopify::Liquid::Token::Number"
not $token->[0]{"arguments"}[0] or ref $token->[0]{"arguments"}[0] ne "WWW::Shopify::Liquid::Token::String" and ref $token->[0]{"arguments"}[0] ne "WWW::Shopify::Liquid::Token::Number"
ref $token->[0]{"arguments"}[0] ne "WWW::Shopify::Liquid::Token::String" and ref $token->[0]{"arguments"}[0] ne "WWW::Shopify::Liquid::Token::Number"
MC/DC0%0/4
$token->[0]->tag eq "when" and !$token->[0]{"arguments"}[0] || ref $token->[0]{"arguments"}[0] ne "WWW::Shopify::Liquid::Token::String" && ref $token->[0]{"arguments"}[0] ne "WWW::Shopify::Liquid::Token::Number"
$token->[0]->tag eq "when"
not $token->[0]{"arguments"}[0]
ref $token->[0]{"arguments"}[0] ne "WWW::Shopify::Liquid::Token::String"
ref $token->[0]{"arguments"}[0] ne "WWW::Shopify::Liquid::Token::Number"
Truth table0%0/5
A and not(B) or C and D
A= $token->[0]->tag eq "when"B= not $token->[0]{"arguments"}[0]C= ref $token->[0]{"arguments"}[0] ne "WWW::Shopify::Liquid::Token::String"D= ref $token->[0]{"arguments"}[0] ne "WWW::Shopify::Liquid::Token::Number"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | die new WWW::Shopify::Liquid::Exception::Parser($self, "Else statements can only be used in the last block of a case statement.") if | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$token->[0]->tag eq "else" and $_ < $#tokens
MC/DC0%0/2
$token->[0]->tag eq "else" and $_ < $#tokens
$token->[0]->tag eq "else"
$_ < $#tokens
Truth table0%0/3
A and B
A= $token->[0]->tag eq "else"B= $_ < $#tokens
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | $token->[0]->tag eq "else" && $_ < $#tokens; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | if ($token->[0]->tag eq "when") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | $self->{paths}->{$token->[0]->{arguments}->[0]->{core}} = $token->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | $self->{else} = $token->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | sub render { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | my ($self, $renderer, $hash) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | my $arguments = $self->{arguments}->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | $arguments = $arguments->render($renderer, $hash) if !$self->is_processed($arguments); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | my $path = $self->{paths}->{$arguments} ? $self->{paths}->{$arguments} : $self->{else}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | $path = $path->render($renderer, $hash) if $path && !$self->is_processed($path); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$path and not $self->is_processed($path)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | return defined $path ? $path : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | sub optimize { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | my ($self, $optimizer, $hash) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
optimize: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | $self->{arguments}->[0] = $self->{arguments}->[0]->optimize($optimizer, $hash) if !$self->is_processed($self->{arguments}->[0]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my $key = $self->{arguments}->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if ($self->is_processed($key)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | my $path = exists $self->{paths}->{$key} ? $self->{paths}->{$key} : $self->{else}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | return $self->is_processed($path) ? $path : $path->optimize($optimizer, $hash); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | $self->{else} = $self->{else}->optimize($optimizer, $hash) if !$self->is_processed($self->{else}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | for (grep { $self->is_processed($self->{paths}->{$_}) } keys(%{$self->{paths}})) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | $self->{paths}->{$_} = $self->{paths}->{$_}->optimize($optimizer, $hash); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 30 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||