File Coverage

blib/lib/Template/Liquid/Tag/Break.pm
Criterion Covered Total %
statement 19 21 90.4
branch 3 6 50.0
condition n/a
subroutine 6 7 85.7
pod 0 2 0.0
total 28 36 77.7


line stmt bran cond sub pod time code
1             package Template::Liquid::Tag::Break;
2             our $VERSION = '1.0.23';
3 25     25   177 use strict;
  25         56  
  25         778  
4 25     25   136 use warnings;
  25         59  
  25         1019  
5             require Template::Liquid::Error;
6             require Template::Liquid::Utility;
7 25     25   146 BEGIN { use base 'Template::Liquid::Tag'; }
  25     0   49  
  25         8979  
  0         0  
8 25     25   109 sub import { Template::Liquid::register_tag('break') }
9              
10             sub new {
11 14     14 0 33 my ($class, $args) = @_;
12             raise Template::Liquid::Error {type => 'Context',
13             template => $args->{template},
14             message => 'Missing template argument',
15             fatal => 1
16             }
17 14 50       74 if !defined $args->{'template'};
18             raise Template::Liquid::Error {type => 'Context',
19             template => $args->{template},
20             message => 'Missing parent argument',
21             fatal => 1
22             }
23 14 50       34 if !defined $args->{'parent'};
24 14 50       34 if ($args->{'attrs'}) {
25             raise Template::Liquid::Error {
26             template => $args->{template},
27             type => 'Syntax',
28 0         0 message => 'Bad argument list in ' . $args->{'markup'},
29             fatal => 1
30             };
31             }
32             my $s = bless {name => '#-' . $1,
33             nodelist => [],
34             tag_name => $args->{'tag_name'},
35             template => $args->{'template'},
36             parent => $args->{'parent'},
37 14         101 markup => $args->{'markup'}
38             }, $class;
39 14         239 return $s;
40             }
41              
42             sub render {
43 4     4 0 8 my $s = shift;
44 4         7 $s->{template}->{break} = 1;
45 4         9 return '';
46             }
47             1;
48              
49             =pod
50              
51             =encoding UTF-8
52              
53             =begin stopwords
54              
55             Lütke jadedPixel
56              
57             =end stopwords
58              
59             =head1 NAME
60              
61             Template::Liquid::Tag::Break - For-block killing construct
62              
63             =head1 Synopsis
64              
65             {% for item in collection %}
66             {% if item.condition %}
67             {% break %}
68             {% endif %}
69             {% endfor %}
70              
71             =head1 Description
72              
73             You can use the C<{% break %}> tag to break out of the enclosing
74             L<for|Template::Liquid::Tag::For> block. Every for block is implicitly ended
75             with a break.
76              
77             =head1 See Also
78              
79             Liquid for Designers: http://wiki.github.com/tobi/liquid/liquid-for-designers
80              
81             L<Template::Liquid|Template::Liquid/"Create your own filters">'s docs on custom
82             filter creation
83              
84             =head1 Author
85              
86             Sanko Robinson <sanko@cpan.org> - http://sankorobinson.com/
87              
88             The original Liquid template system was developed by jadedPixel
89             (http://jadedpixel.com/) and Tobias Lütke (http://blog.leetsoft.com/).
90              
91             =head1 License and Legal
92              
93             Copyright (C) 2009-2022 by Sanko Robinson E<lt>sanko@cpan.orgE<gt>
94              
95             This program is free software; you can redistribute it and/or modify it under
96             the terms of The Artistic License 2.0. See the F<LICENSE> file included with
97             this distribution or http://www.perlfoundation.org/artistic_license_2_0. For
98             clarification, see http://www.perlfoundation.org/artistic_2_0_notes.
99              
100             When separated from the distribution, all original POD documentation is covered
101             by the Creative Commons Attribution-Share Alike 3.0 License. See
102             http://creativecommons.org/licenses/by-sa/3.0/us/legalcode. For clarification,
103             see http://creativecommons.org/licenses/by-sa/3.0/us/.
104              
105             =cut