line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
our $VERSION = '1.0.21'; |
2
|
|
|
|
|
|
|
use strict; |
3
|
24
|
|
|
24
|
|
125
|
use warnings; |
|
24
|
|
|
|
|
43
|
|
|
24
|
|
|
|
|
537
|
|
4
|
24
|
|
|
24
|
|
95
|
use base 'Template::Liquid::Tag::If'; |
|
24
|
|
|
|
|
39
|
|
|
24
|
|
|
|
|
489
|
|
5
|
24
|
|
|
24
|
|
111
|
require Template::Liquid::Error; |
|
24
|
|
|
|
|
35
|
|
|
24
|
|
|
|
|
9026
|
|
6
|
|
|
|
|
|
|
require Template::Liquid::Utility; |
7
|
|
|
|
|
|
|
|
8
|
24
|
|
|
24
|
|
75
|
my ($class, $args) = @_; |
9
|
|
|
|
|
|
|
raise Template::Liquid::Error {type => 'Context', |
10
|
|
|
|
|
|
|
template => $args->{template}, |
11
|
11
|
|
|
11
|
0
|
18
|
message => 'Missing template argument', |
12
|
|
|
|
|
|
|
fatal => 1 |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
if !defined $args->{'template'}; |
15
|
|
|
|
|
|
|
raise Template::Liquid::Error {type => 'Context', |
16
|
|
|
|
|
|
|
template => $args->{template}, |
17
|
11
|
50
|
|
|
|
24
|
message => 'Missing parent argument', |
18
|
|
|
|
|
|
|
fatal => 1 |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
if !defined $args->{'parent'}; |
21
|
|
|
|
|
|
|
raise Template::Liquid::Error { |
22
|
|
|
|
|
|
|
type => 'Syntax', |
23
|
11
|
50
|
|
|
|
24
|
template => $args->{template}, |
24
|
|
|
|
|
|
|
message => 'Missing argument list in ' . $args->{'markup'}, |
25
|
|
|
|
|
|
|
fatal => 1 |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
if !defined $args->{'attrs'}; |
28
|
|
|
|
|
|
|
if ($args->{'attrs'} !~ m[\S$]o) { |
29
|
|
|
|
|
|
|
raise Template::Liquid::Error { |
30
|
11
|
50
|
|
|
|
26
|
type => 'Syntax', |
31
|
11
|
50
|
|
|
|
34
|
template => $args->{template}, |
32
|
|
|
|
|
|
|
message => 'Bad argument list in ' . $args->{'markup'}, |
33
|
|
|
|
|
|
|
fatal => 1 |
34
|
|
|
|
|
|
|
}; |
35
|
0
|
|
|
|
|
0
|
} |
36
|
|
|
|
|
|
|
my $s = bless {name => $args->{'tag_name'} . '-' . $args->{'attrs'}, |
37
|
|
|
|
|
|
|
blocks => [], |
38
|
|
|
|
|
|
|
tag_name => $args->{'tag_name'}, |
39
|
|
|
|
|
|
|
template => $args->{'template'}, |
40
|
|
|
|
|
|
|
parent => $args->{'parent'}, |
41
|
|
|
|
|
|
|
markup => $args->{'markup'}, |
42
|
|
|
|
|
|
|
value => $args->{'attrs'}, |
43
|
|
|
|
|
|
|
first_block => 0, |
44
|
|
|
|
|
|
|
end_tag => 'end' . $args->{'tag_name'}, |
45
|
|
|
|
|
|
|
conditional_tag => qr[^(?:else|when)$]o |
46
|
|
|
|
|
|
|
}, $class; |
47
|
11
|
|
|
|
|
281
|
return $s; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
11
|
|
|
|
|
38
|
my ($s, $args) = @_; |
51
|
|
|
|
|
|
|
raise Template::Liquid::Error {type => 'Context', |
52
|
|
|
|
|
|
|
template => $s->{template}, |
53
|
|
|
|
|
|
|
message => 'Missing template argument', |
54
|
26
|
|
|
26
|
0
|
58
|
fatal => 1 |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
if !defined $args->{'template'}; |
57
|
|
|
|
|
|
|
raise Template::Liquid::Error {type => 'Context', |
58
|
|
|
|
|
|
|
template => $s->{template}, |
59
|
|
|
|
|
|
|
message => 'Missing parent argument', |
60
|
26
|
50
|
|
|
|
54
|
fatal => 1 |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
if !defined $args->{'parent'}; |
63
|
|
|
|
|
|
|
raise Template::Liquid::Error { |
64
|
|
|
|
|
|
|
type => 'Syntax', |
65
|
|
|
|
|
|
|
template => $s->{template}, |
66
|
26
|
50
|
|
|
|
44
|
message => 'Missing argument list in ' . $args->{'markup'}, |
67
|
|
|
|
|
|
|
fatal => 1 |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
if !defined $args->{'attrs'} && $args->{'tag_name'} eq 'when'; |
70
|
|
|
|
|
|
|
if ($args->{'tag_name'} eq 'when') { |
71
|
|
|
|
|
|
|
$args->{'attrs'} = join ' or ', |
72
|
|
|
|
|
|
|
map { sprintf '%s == %s', $args->{'parent'}{'value'}, $_ } |
73
|
26
|
50
|
66
|
|
|
71
|
grep { defined $_ } |
74
|
26
|
100
|
|
|
|
49
|
$args->{'attrs'} =~ m[(${Template::Liquid::Utility::Expression}) |
75
|
|
|
|
|
|
|
(?:\s+or\s+|\s*\,\s*)?]oxmg; |
76
|
32
|
|
|
|
|
132
|
} |
77
|
32
|
|
|
|
|
75
|
my $block |
78
|
23
|
|
|
|
|
599
|
= Template::Liquid::Block->new( |
79
|
|
|
|
|
|
|
{tag_name => $args->{'tag_name'}, |
80
|
|
|
|
|
|
|
end_tag => 'end' . $args->{'tag_name'}, |
81
|
|
|
|
|
|
|
attrs => $args->{'attrs'}, |
82
|
|
|
|
|
|
|
template => $args->{'template'}, |
83
|
|
|
|
|
|
|
parent => $s |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
); |
86
|
26
|
|
|
|
|
130
|
|
87
|
|
|
|
|
|
|
# finish previous block if it exists |
88
|
|
|
|
|
|
|
${$s->{'blocks'}[-1]}{'nodelist'} = $s->{'nodelist'} |
89
|
|
|
|
|
|
|
if scalar @{$s->{'blocks'}}; |
90
|
|
|
|
|
|
|
$s->{'nodelist'} = []; # Unline {%if%}, we *always* empty the |
91
|
|
|
|
|
|
|
|
92
|
26
|
|
|
|
|
47
|
# nodelist. This way, we ignore nodes that come before the first |
93
|
26
|
50
|
|
|
|
47
|
# when/else block just like Liquid |
|
26
|
|
|
|
|
61
|
|
94
|
26
|
|
|
|
|
40
|
push @{$s->{'blocks'}}, $block; |
95
|
|
|
|
|
|
|
shift @{$s->{'blocks'}} # S::D->parse() pushes a dead first block |
96
|
|
|
|
|
|
|
if $s->{'first_block'}++ == 0; |
97
|
|
|
|
|
|
|
return $block; |
98
|
26
|
|
|
|
|
30
|
} |
|
26
|
|
|
|
|
39
|
|
99
|
11
|
|
|
|
|
16
|
1; |
100
|
26
|
100
|
|
|
|
53
|
|
101
|
26
|
|
|
|
|
53
|
=pod |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=encoding UTF-8 |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=begin stopwords |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Lütke jadedPixel |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=end stopwords |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 NAME |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Template::Liquid::Tag::Case - Switch Statement Construct |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 Description |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
If you need more conditions, you can use the C<case> tag. Note that, stuff that |
118
|
|
|
|
|
|
|
comes before the first C<when> or C<else> is ignored. ...just as it is in |
119
|
|
|
|
|
|
|
Liquid. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 Synopsis |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
{% case condition %} |
124
|
|
|
|
|
|
|
{% when 1 %} |
125
|
|
|
|
|
|
|
hit 1 |
126
|
|
|
|
|
|
|
{% when 2 or 3 %} |
127
|
|
|
|
|
|
|
hit 2 or 3 |
128
|
|
|
|
|
|
|
{% else %} |
129
|
|
|
|
|
|
|
... else ... |
130
|
|
|
|
|
|
|
{% endcase %} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
...or even... |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
{% case template %} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
{% when 'label' %} |
137
|
|
|
|
|
|
|
// {{ label.title }} |
138
|
|
|
|
|
|
|
{% when 'product' %} |
139
|
|
|
|
|
|
|
// {{ product.vendor | link_to_vendor }} / {{ product.title }} |
140
|
|
|
|
|
|
|
{% else %} |
141
|
|
|
|
|
|
|
// {{page_title} |
142
|
|
|
|
|
|
|
{% endcase %} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 Author |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Sanko Robinson <sanko@cpan.org> - http://sankorobinson.com/ |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
The original Liquid template system was developed by jadedPixel |
149
|
|
|
|
|
|
|
(http://jadedpixel.com/) and Tobias Lütke (http://blog.leetsoft.com/). |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 License and Legal |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Copyright (C) 2009-2022 by Sanko Robinson E<lt>sanko@cpan.orgE<gt> |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under |
156
|
|
|
|
|
|
|
the terms of The Artistic License 2.0. See the F<LICENSE> file included with |
157
|
|
|
|
|
|
|
this distribution or http://www.perlfoundation.org/artistic_license_2_0. For |
158
|
|
|
|
|
|
|
clarification, see http://www.perlfoundation.org/artistic_2_0_notes. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
When separated from the distribution, all original POD documentation is covered |
161
|
|
|
|
|
|
|
by the Creative Commons Attribution-Share Alike 3.0 License. See |
162
|
|
|
|
|
|
|
http://creativecommons.org/licenses/by-sa/3.0/us/legalcode. For clarification, |
163
|
|
|
|
|
|
|
see http://creativecommons.org/licenses/by-sa/3.0/us/. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=cut |