File Coverage

blib/lib/Template/Liquid/Utility.pm
Criterion Covered Total %
statement 11 11 100.0
branch 1 2 50.0
condition 1 2 50.0
subroutine 4 4 100.0
pod 0 1 0.0
total 17 20 85.0


line stmt bran cond sub pod time code
1             package Template::Liquid::Utility;
2 26     26   13486 use experimental 'signatures';
  26         95554  
  26         139  
3 26     26   4505 use strict;
  26         67  
  26         560  
4 26     26   139 use warnings;
  26         50  
  26         26188  
5             our $VERSION = '1.0.23';
6             our $FilterSeparator = qr[\s*\|\s*]o;
7             my $ArgumentSeparator = qr[,]o;
8             our $FilterArgumentSeparator = qr[\s*:\s*]o;
9             our $VariableAttributeSeparator = qr[\.]o;
10             our $TagStart = qr[(?:\s*{%-\s*|{%\s*)]o;
11             our $TagEnd = qr[(?:\s*-%}\s*|\s*%})]o;
12             our $VariableSignature = qr{\(?[\w\-\.\[\]]\)?}o;
13             my $VariableSegment = qr[[\w\-]\??]ox;
14             our $VariableStart = qr[(?:\s*\{\{-\s*|\{\{-?\s*)]o;
15             our $VariableEnd = qr[(?:\s*-?}}\s*?|\s*}})]o;
16             my $VariableIncompleteEnd = qr[(?:\s*-}}?\s*|}})];
17             my $QuotedString = qr/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/o;
18             our $QuotedFragment = qr/${QuotedString}|(?:[^\s,\|'"]|${QuotedString})+/o;
19             my $StrictQuotedFragment = qr/"[^"]+"|'[^']+'|[^\s,\|,\:,\,]+/o;
20             my $FirstFilterArgument
21             = qr/${FilterArgumentSeparator}(?:${StrictQuotedFragment})/o;
22             my $OtherFilterArgument
23             = qr/${ArgumentSeparator}(?:${StrictQuotedFragment})/o;
24             my $SpacelessFilter
25             = qr/${FilterSeparator}(?:${StrictQuotedFragment})(?:${FirstFilterArgument}(?:${OtherFilterArgument})*)?/o;
26             our $Expression = qr/(?:${QuotedFragment}(?:${SpacelessFilter})*)/o;
27             our $TagAttributes = qr[(\w+)(?:\s*\:\s*(${QuotedFragment}))?]o;
28             my $AnyStartingTag = qr[\{\{|\{\%]o;
29             my $PartialTemplateParser
30             = qr[${TagStart}.+?${TagEnd}|${VariableStart}.+?${VariableIncompleteEnd}]os;
31             my $TemplateParser = qr[(${PartialTemplateParser}|${AnyStartingTag})]os;
32             our $VariableParser
33             = qr[${VariableStart}([\w\.]+)(?:\s*\|\s*(.+)\s*)?${VariableEnd}$]so;
34             our $VariableFilterArgumentParser = qr[
35             (?:
36             (?:\s*,\s*)?
37             (?:
38             ((?:\")(?:[^\\\"]*(?:\\.[^\\\"]*)*)(?:\"))
39             |((?:\')(?:[^\\\']*(?:\\.[^\\\']*)*)(?:\'))
40             |(?:([^,]+)(?:\s*,\s*)?)
41             )
42             )]smx;
43             our $TagMatch = qr[^${Template::Liquid::Utility::TagStart} # {%
44             (.+?) # etc
45             ${Template::Liquid::Utility::TagEnd} # %}
46             $]sox;
47             our $VarMatch = qr[^${Template::Liquid::Utility::VariableStart} # {{
48             (.+?) # stuff + filters?
49             ${Template::Liquid::Utility::VariableEnd} # }}
50             $]sox;
51              
52             sub tokenize {
53 369 50 50 369 0 7833 map { defined $_ ? $_ : () } split $TemplateParser, shift || '';
  2090         5249  
54             }
55             1;
56              
57             =pod
58              
59             =encoding UTF-8
60              
61             =begin stopwords
62              
63             Lütke jadedPixel
64              
65             =end stopwords
66              
67             =head1 NAME
68              
69             Template::Liquid::Utility - Utility stuff. Watch your step.
70              
71             =head1 Description
72              
73             It's best to just forget this package exists. It's messy but seems to work.
74              
75             =head1 See Also
76              
77             Liquid for Designers: http://wiki.github.com/tobi/liquid/liquid-for-designers
78              
79             L<Template::Liquid|Template::Liquid/"Create your own filters">'s docs on custom
80             filter creation
81              
82             =head1 Author
83              
84             Sanko Robinson <sanko@cpan.org> - http://sankorobinson.com/
85              
86             The original Liquid template system was developed by jadedPixel
87             (http://jadedpixel.com/) and Tobias Lütke (http://blog.leetsoft.com/).
88              
89             =head1 License and Legal
90              
91             Copyright (C) 2009-2022 by Sanko Robinson E<lt>sanko@cpan.orgE<gt>
92              
93             This program is free software; you can redistribute it and/or modify it under
94             the terms of The Artistic License 2.0. See the F<LICENSE> file included with
95             this distribution or http://www.perlfoundation.org/artistic_license_2_0. For
96             clarification, see http://www.perlfoundation.org/artistic_2_0_notes.
97              
98             When separated from the distribution, all original POD documentation is covered
99             by the Creative Commons Attribution-Share Alike 3.0 License. See
100             http://creativecommons.org/licenses/by-sa/3.0/us/legalcode. For clarification,
101             see http://creativecommons.org/licenses/by-sa/3.0/us/.
102              
103             =cut