line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
our $VERSION = '1.0.22'; |
2
|
|
|
|
|
|
|
use strict; |
3
|
24
|
|
|
24
|
|
132
|
use warnings; |
|
24
|
|
|
|
|
43
|
|
|
24
|
|
|
|
|
577
|
|
4
|
24
|
|
|
24
|
|
136
|
use base 'Template::Liquid::Tag::If'; |
|
24
|
|
|
|
|
35
|
|
|
24
|
|
|
|
|
513
|
|
5
|
24
|
|
|
24
|
|
99
|
require Template::Liquid::Error; |
|
24
|
|
|
|
|
40
|
|
|
24
|
|
|
|
|
9622
|
|
6
|
|
|
|
|
|
|
require Template::Liquid::Utility; |
7
|
|
|
|
|
|
|
|
8
|
24
|
|
|
24
|
|
81
|
my ($class, $args) = @_; |
9
|
|
|
|
|
|
|
raise Template::Liquid::Error {type => 'Context', |
10
|
|
|
|
|
|
|
template => $args->{template}, |
11
|
11
|
|
|
11
|
0
|
21
|
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
|
|
|
|
27
|
message => 'Missing parent argument', |
18
|
|
|
|
|
|
|
fatal => 1 |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
if !defined $args->{'parent'}; |
21
|
|
|
|
|
|
|
raise Template::Liquid::Error { |
22
|
|
|
|
|
|
|
type => 'Syntax', |
23
|
11
|
50
|
|
|
|
23
|
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
|
|
|
|
28
|
type => 'Syntax', |
31
|
11
|
50
|
|
|
|
36
|
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
|
|
|
|
|
307
|
return $s; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
11
|
|
|
|
|
34
|
my ($s, $args) = @_; |
51
|
|
|
|
|
|
|
raise Template::Liquid::Error {type => 'Context', |
52
|
|
|
|
|
|
|
template => $s->{template}, |
53
|
|
|
|
|
|
|
message => 'Missing template argument', |
54
|
26
|
|
|
26
|
0
|
49
|
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
|
|
|
|
48
|
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
|
|
|
76
|
grep { defined $_ } |
74
|
26
|
100
|
|
|
|
51
|
$args->{'attrs'} =~ m[(${Template::Liquid::Utility::Expression}) |
75
|
|
|
|
|
|
|
(?:\s+or\s+|\s*\,\s*)?]oxmg; |
76
|
32
|
|
|
|
|
140
|
} |
77
|
32
|
|
|
|
|
82
|
my $block |
78
|
23
|
|
|
|
|
545
|
= 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
|
|
|
|
|
134
|
|
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
|
|
|
|
|
53
|
# nodelist. This way, we ignore nodes that come before the first |
93
|
26
|
50
|
|
|
|
45
|
# when/else block just like Liquid |
|
26
|
|
|
|
|
59
|
|
94
|
26
|
|
|
|
|
39
|
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
|
|
|
|
|
42
|
|
99
|
11
|
|
|
|
|
16
|
1; |
100
|
26
|
100
|
|
|
|
50
|
|
101
|
26
|
|
|
|
|
52
|
=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 |