| 1 | package Template::Liquid::Utility; | ||||||||||||||||||||
| 2 | 25 | ▶ | use experimental 'signatures'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 25 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 25 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 25 | our $VERSION = '1.0.22'; | |||||||||||||||||||
| 6 | 25 | our $FilterSeparator = qr[\s*\|\s*]o; | |||||||||||||||||||
| 7 | 25 | my $ArgumentSeparator = qr[,]o; | |||||||||||||||||||
| 8 | 25 | our $FilterArgumentSeparator = qr[\s*:\s*]o; | |||||||||||||||||||
| 9 | 25 | our $VariableAttributeSeparator = qr[\.]o; | |||||||||||||||||||
| 10 | 25 | our $TagStart = qr[(?:\s*{%-\s*|{%\s*)]o; | |||||||||||||||||||
| 11 | 25 | our $TagEnd = qr[(?:\s*-%}\s*|\s*%})]o; | |||||||||||||||||||
| 12 | 25 | our $VariableSignature = qr{\(?[\w\-\.\[\]]\)?}o; | |||||||||||||||||||
| 13 | 25 | my $VariableSegment = qr[[\w\-]\??]ox; | |||||||||||||||||||
| 14 | 25 | our $VariableStart = qr[(?:\s*\{\{-\s*|\{\{-?\s*)]o; | |||||||||||||||||||
| 15 | 25 | our $VariableEnd = qr[(?:\s*-?}}\s*?|\s*}})]o; | |||||||||||||||||||
| 16 | 25 | my $VariableIncompleteEnd = qr[(?:\s*-}}?\s*|}})]; | |||||||||||||||||||
| 17 | 25 | my $QuotedString = qr/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/o; | |||||||||||||||||||
| 18 | 25 | our $QuotedFragment = qr/${QuotedString}|(?:[^\s,\|'"]|${QuotedString})+/o; | |||||||||||||||||||
| 19 | 25 | my $StrictQuotedFragment = qr/"[^"]+"|'[^']+'|[^\s,\|,\:,\,]+/o; | |||||||||||||||||||
| 20 | 25 | my $FirstFilterArgument | |||||||||||||||||||
| 21 | = qr/${FilterArgumentSeparator}(?:${StrictQuotedFragment})/o; | ||||||||||||||||||||
| 22 | 25 | my $OtherFilterArgument | |||||||||||||||||||
| 23 | = qr/${ArgumentSeparator}(?:${StrictQuotedFragment})/o; | ||||||||||||||||||||
| 24 | 25 | my $SpacelessFilter | |||||||||||||||||||
| 25 | = qr/${FilterSeparator}(?:${StrictQuotedFragment})(?:${FirstFilterArgument}(?:${OtherFilterArgument})*)?/o; | ||||||||||||||||||||
| 26 | 25 | our $Expression = qr/(?:${QuotedFragment}(?:${SpacelessFilter})*)/o; | |||||||||||||||||||
| 27 | 25 | our $TagAttributes = qr[(\w+)(?:\s*\:\s*(${QuotedFragment}))?]o; | |||||||||||||||||||
| 28 | 25 | my $AnyStartingTag = qr[\{\{|\{\%]o; | |||||||||||||||||||
| 29 | 25 | my $PartialTemplateParser | |||||||||||||||||||
| 30 | = qr[${TagStart}.+?${TagEnd}|${VariableStart}.+?${VariableIncompleteEnd}]os; | ||||||||||||||||||||
| 31 | 25 | my $TemplateParser = qr[(${PartialTemplateParser}|${AnyStartingTag})]os; | |||||||||||||||||||
| 32 | 25 | our $VariableParser | |||||||||||||||||||
| 33 | = qr[${VariableStart}([\w\.]+)(?:\s*\|\s*(.+)\s*)?${VariableEnd}$]so; | ||||||||||||||||||||
| 34 | 25 | our $VariableFilterArgumentParser = qr[ | |||||||||||||||||||
| 35 | (?: | ||||||||||||||||||||
| 36 | (?:\s*,\s*)? | ||||||||||||||||||||
| 37 | (?: | ||||||||||||||||||||
| 38 | ((?:\")(?:[^\\\"]*(?:\\.[^\\\"]*)*)(?:\")) | ||||||||||||||||||||
| 39 | |((?:\')(?:[^\\\']*(?:\\.[^\\\']*)*)(?:\')) | ||||||||||||||||||||
| 40 | |(?:([^,]+)(?:\s*,\s*)?) | ||||||||||||||||||||
| 41 | ) | ||||||||||||||||||||
| 42 | )]smx; | ||||||||||||||||||||
| 43 | 25 | our $TagMatch = qr[^${Template::Liquid::Utility::TagStart} # {% | |||||||||||||||||||
| 44 | (.+?) # etc | ||||||||||||||||||||
| 45 | ${Template::Liquid::Utility::TagEnd} # %} | ||||||||||||||||||||
| 46 | $]sox; | ||||||||||||||||||||
| 47 | 25 | our $VarMatch = qr[^${Template::Liquid::Utility::VariableStart} # {{ | |||||||||||||||||||
| 48 | (.+?) # stuff + filters? | ||||||||||||||||||||
| 49 | ${Template::Liquid::Utility::VariableEnd} # }} | ||||||||||||||||||||
| 50 | $]sox; | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | sub tokenize { | ||||||||||||||||||||
| 53 | 359 | ▶ | map { defined $_ ? $_ : () } split $TemplateParser, shift || ''; | ||||||||||||||||||
|
Subroutine
tokenize: called CC=3 SCAR=12.0
Pod
undocumented
Branch: 1 branch
Condition50%1/2
shift() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | 25 | 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 | ||||||||||||||||||||