line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
21
|
|
|
21
|
|
125
|
use strict; |
|
21
|
|
|
|
|
40
|
|
|
21
|
|
|
|
|
746
|
|
3
|
21
|
|
|
21
|
|
1418
|
use warnings; |
|
21
|
|
|
|
|
42
|
|
|
21
|
|
|
|
|
872
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package WWW::Shopify::Liquid::Tag::If; |
6
|
21
|
|
|
21
|
|
100
|
use base 'WWW::Shopify::Liquid::Tag::Enclosing'; |
|
21
|
|
|
|
|
27
|
|
|
21
|
|
|
|
|
3741
|
|
7
|
|
|
|
|
|
|
|
8
|
0
|
|
|
0
|
0
|
0
|
sub min_arguments { return 1; } |
9
|
0
|
|
|
0
|
0
|
0
|
sub max_arguments { return 1; } |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
48
|
|
|
48
|
0
|
94
|
my $package = shift; |
13
|
48
|
|
|
|
|
359
|
my $self = bless { |
14
|
|
|
|
|
|
|
line => shift, |
15
|
|
|
|
|
|
|
core => shift, |
16
|
|
|
|
|
|
|
arguments => shift, |
17
|
|
|
|
|
|
|
true_path => undef, |
18
|
|
|
|
|
|
|
false_path => undef |
19
|
|
|
|
|
|
|
}, $package; |
20
|
48
|
|
|
|
|
73
|
$self->interpret_inner_tokens(@{$_[0]}); |
|
48
|
|
|
|
|
207
|
|
21
|
48
|
|
|
|
|
132
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
95
|
|
|
95
|
0
|
302
|
sub inner_tags { return qw(elsif else) } |
24
|
21
|
|
|
21
|
|
124
|
use List::Util qw(first); |
|
21
|
|
|
|
|
31
|
|
|
21
|
|
|
|
|
10530
|
|
25
|
|
|
|
|
|
|
sub interpret_inner_tokens { |
26
|
48
|
|
|
48
|
0
|
106
|
my ($self, @tokens) = @_; |
27
|
|
|
|
|
|
|
# Comes in [true_path], [tag, other_path], [tag, other_path], ... |
28
|
48
|
|
|
|
|
85
|
my $token = shift(@tokens); |
29
|
48
|
50
|
|
|
|
128
|
return undef unless $token; |
30
|
48
|
|
|
|
|
215
|
$self->{true_path} = $token->[0]; |
31
|
48
|
100
|
|
|
|
156
|
if (int(@tokens) > 0) { |
32
|
20
|
50
|
66
|
|
|
100
|
die new WWW::Shopify::Liquid::Exception::Parser($self, "else cannot be anywhere, except the end tag of an if statement.") if $tokens[0]->[0]->tag eq "else" && int(@tokens) > 1; |
33
|
20
|
100
|
|
|
|
79
|
if ($tokens[0]->[0]->tag eq "elsif") { |
34
|
2
|
|
|
|
|
6
|
my @inner_tokens = @{$tokens[0]}; |
|
2
|
|
|
|
|
6
|
|
35
|
2
|
|
|
|
|
22
|
$self->{false_path} = WWW::Shopify::Liquid::Tag::If->new($tokens[0]->[0]->{line}, "if", shift(@inner_tokens)->{arguments}, [\@inner_tokens]); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
else { |
38
|
18
|
|
|
|
|
57
|
$self->{false_path} = $tokens[0]->[1]; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
0
|
0
|
0
|
sub tokens { return ($_[0], map { $_->tokens } grep { defined $_ } ($_[0]->{true_path}, $_[0]->{false_path}, @{$_[0]->{arguments}})) } |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub render { |
46
|
15
|
|
|
15
|
0
|
24
|
my ($self, $hash) = @_; |
47
|
15
|
50
|
|
|
|
54
|
my $arguments = $self->is_processed($self->{arguments}->[0]) ? $self->{arguments}->[0] : $self->{arguments}->[0]->render($hash); |
48
|
15
|
100
|
|
|
|
39
|
my $path = $self->{$arguments ? 'true_path' : 'false_path'}; |
49
|
15
|
100
|
66
|
|
|
43
|
$path = $path->render($hash) if $path && !$self->is_processed($path); |
50
|
15
|
100
|
|
|
|
50
|
return defined $path ? $path : ''; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub optimize { |
54
|
0
|
|
|
0
|
0
|
|
my ($self, $hash) = @_; |
55
|
0
|
0
|
|
|
|
|
$self->{arguments}->[0] = $self->{arguments}->[0]->optimize($hash) if !$self->is_processed($self->{arguments}->[0]); |
56
|
0
|
0
|
|
|
|
|
if ($self->is_processed($self->{arguments}->[0])) { |
57
|
0
|
0
|
|
|
|
|
my $path = $self->{$self->{arguments}->[0] ? 'true_path' : 'false_path'}; |
58
|
0
|
0
|
|
|
|
|
return $self->is_processed($path) ? $path : $path->optimize($hash); |
59
|
|
|
|
|
|
|
} |
60
|
0
|
0
|
|
|
|
|
$self->{false_path} = $self->{false_path}->optimize($hash) if !$self->is_processed($self->{false_path}); |
61
|
0
|
0
|
|
|
|
|
$self->{true_path} = $self->{true_path}->optimize($hash) if !$self->is_processed($self->{true_path}); |
62
|
0
|
|
|
|
|
|
return $self; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |