| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Template::Liquid::Document; | 
| 2 |  |  |  |  |  |  | our $VERSION = '1.0.23'; | 
| 3 | 25 |  |  | 25 |  | 179 | use strict; | 
|  | 25 |  |  |  |  | 62 |  | 
|  | 25 |  |  |  |  | 746 |  | 
| 4 | 25 |  |  | 25 |  | 126 | use warnings; | 
|  | 25 |  |  |  |  | 65 |  | 
|  | 25 |  |  |  |  | 667 |  | 
| 5 | 25 |  |  | 25 |  | 12509 | use Template::Liquid::Variable; | 
|  | 25 |  |  |  |  | 71 |  | 
|  | 25 |  |  |  |  | 843 |  | 
| 6 | 25 |  |  | 25 |  | 11012 | use Template::Liquid::Utility; | 
|  | 25 |  |  |  |  | 91 |  | 
|  | 25 |  |  |  |  | 22381 |  | 
| 7 |  |  |  |  |  |  | # | 
| 8 |  |  |  |  |  |  | sub new { | 
| 9 | 369 |  |  | 369 | 0 | 842 | my ($class, $args) = @_; | 
| 10 |  |  |  |  |  |  | raise Template::Liquid::Error {type     => 'Context', | 
| 11 |  |  |  |  |  |  | template => (), | 
| 12 |  |  |  |  |  |  | message  => 'Missing template argument', | 
| 13 |  |  |  |  |  |  | fatal    => 1 | 
| 14 |  |  |  |  |  |  | } | 
| 15 | 369 | 50 |  |  |  | 946 | if !defined $args->{'template'}; | 
| 16 |  |  |  |  |  |  | return | 
| 17 |  |  |  |  |  |  | bless {template => $args->{'template'}, | 
| 18 | 369 |  |  |  |  | 2059 | parent   => $args->{'template'} | 
| 19 |  |  |  |  |  |  | }, $class; | 
| 20 |  |  |  |  |  |  | } | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | sub parse { | 
| 23 | 608 |  |  | 608 | 0 | 1078 | my ($class, $args, $tokens); | 
| 24 | 608 | 50 |  |  |  | 1819 | (scalar @_ == 3 ? ($class, $args, $tokens) : ($class, $tokens)) = @_; | 
| 25 | 608 | 50 |  |  |  | 1392 | my $s     = ref $class ? $class : $class->new($args); | 
| 26 | 608 |  |  |  |  | 1719 | my %_tags = $s->{template}->tags; | 
| 27 | 608 |  |  |  |  | 1502 | NODE: while (defined(my $token = shift @{$tokens})) { | 
|  | 2459 |  |  |  |  | 10031 |  | 
| 28 | 2090 | 100 |  |  |  | 14136 | if ($token =~ $Template::Liquid::Utility::TagMatch) { | 
|  |  | 100 |  |  |  |  |  | 
| 29 | 649 |  |  |  |  | 2473 | my ($tag, $attrs) = (split ' ', $1, 2); | 
| 30 | 649 |  |  |  |  | 1390 | my $package = $_tags{$tag}; | 
| 31 | 649 | 100 |  |  |  | 2851 | my $call    = $package ? $package->can('new') : (); | 
| 32 | 649 | 100 | 66 |  |  | 2600 | if (defined $call) { | 
|  |  | 100 | 33 |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | my $_tag = $call->($package, | 
| 34 |  |  |  |  |  |  | {template => $s->{template}, | 
| 35 | 347 |  |  |  |  | 2125 | parent   => $s, | 
| 36 |  |  |  |  |  |  | tag_name => $tag, | 
| 37 |  |  |  |  |  |  | markup   => $token, | 
| 38 |  |  |  |  |  |  | attrs    => $attrs | 
| 39 |  |  |  |  |  |  | } | 
| 40 |  |  |  |  |  |  | ); | 
| 41 | 347 |  |  |  |  | 946 | push @{$s->{'nodelist'}}, $_tag; | 
|  | 347 |  |  |  |  | 756 |  | 
| 42 | 347 | 100 |  |  |  | 1148 | if ($_tag->conditional_tag) { | 
|  |  | 100 |  |  |  |  |  | 
| 43 | 213 |  |  |  |  | 1103 | push @{$_tag->{'blocks'}}, | 
| 44 |  |  |  |  |  |  | Template::Liquid::Block->new( | 
| 45 |  |  |  |  |  |  | {tag_name => $tag, | 
| 46 |  |  |  |  |  |  | attrs    => $attrs, | 
| 47 |  |  |  |  |  |  | template => $_tag->{template}, | 
| 48 | 213 |  |  |  |  | 338 | parent   => $_tag | 
| 49 |  |  |  |  |  |  | } | 
| 50 |  |  |  |  |  |  | ); | 
| 51 | 213 |  |  |  |  | 1031 | $_tag->parse($tokens); | 
| 52 |  |  |  |  |  |  | {    # finish previous block | 
| 53 | 213 |  |  |  |  | 314 | ${$_tag->{'blocks'}[-1]}{'nodelist'} | 
|  | 213 |  |  |  |  | 539 |  | 
| 54 | 213 |  |  |  |  | 342 | = $_tag->{'nodelist'}; | 
| 55 | 213 |  |  |  |  | 522 | $_tag->{'nodelist'} = []; | 
| 56 |  |  |  |  |  |  | } | 
| 57 |  |  |  |  |  |  | } | 
| 58 |  |  |  |  |  |  | elsif ($_tag->end_tag) { | 
| 59 | 26 |  |  |  |  | 193 | $_tag->parse($tokens); | 
| 60 |  |  |  |  |  |  | } | 
| 61 |  |  |  |  |  |  | } | 
| 62 |  |  |  |  |  |  | elsif ($s->can('end_tag') && $tag =~ $s->end_tag) { | 
| 63 | 239 |  |  |  |  | 627 | $s->{'markup_2'} = $token; | 
| 64 | 239 |  |  |  |  | 611 | last NODE; | 
| 65 |  |  |  |  |  |  | } | 
| 66 |  |  |  |  |  |  | elsif ($s->conditional_tag && $tag =~ $s->conditional_tag) { | 
| 67 |  |  |  |  |  |  | $s->push_block({tag_name => $tag, | 
| 68 |  |  |  |  |  |  | attrs    => $attrs, | 
| 69 |  |  |  |  |  |  | markup   => $token, | 
| 70 |  |  |  |  |  |  | template => $s->{template}, | 
| 71 | 63 |  |  |  |  | 368 | parent   => $s | 
| 72 |  |  |  |  |  |  | }, | 
| 73 |  |  |  |  |  |  | $tokens | 
| 74 |  |  |  |  |  |  | ); | 
| 75 |  |  |  |  |  |  | } | 
| 76 |  |  |  |  |  |  | else { | 
| 77 |  |  |  |  |  |  | raise Template::Liquid::Error { | 
| 78 |  |  |  |  |  |  | type     => 'Syntax', | 
| 79 |  |  |  |  |  |  | template => $s->{template}, | 
| 80 | 0 |  |  |  |  | 0 | message => 'Unknown tag: ' . $token | 
| 81 |  |  |  |  |  |  | }; | 
| 82 |  |  |  |  |  |  | } | 
| 83 |  |  |  |  |  |  | } | 
| 84 |  |  |  |  |  |  | elsif ($token =~ $Template::Liquid::Utility::VarMatch) { | 
| 85 | 295 |  |  |  |  | 2136 | my ($variable, $filters) = split qr[\s*\|\s*]o, $1, 2; | 
| 86 | 295 |  |  |  |  | 716 | my @filters; | 
| 87 | 295 |  | 100 |  |  | 1390 | for my $filter (split $Template::Liquid::Utility::FilterSeparator, | 
| 88 |  |  |  |  |  |  | $filters || '') { | 
| 89 | 164 |  |  |  |  | 624 | my ($filter, $args) | 
| 90 |  |  |  |  |  |  | = split | 
| 91 |  |  |  |  |  |  | $Template::Liquid::Utility::FilterArgumentSeparator, | 
| 92 |  |  |  |  |  |  | $filter, 2; | 
| 93 | 164 |  |  |  |  | 768 | $filter =~ s[\s*$][]o;    # XXX - the splitter should clean... | 
| 94 | 164 |  |  |  |  | 470 | $filter =~ s[^\s*][]o;    # XXX -  ...this up for us. | 
| 95 |  |  |  |  |  |  | my @args | 
| 96 | 164 | 100 |  |  |  | 879 | = !defined $args ? () : grep { defined $_ } | 
|  | 342 |  |  |  |  | 813 |  | 
| 97 |  |  |  |  |  |  | $args | 
| 98 |  |  |  |  |  |  | =~ m[$Template::Liquid::Utility::VariableFilterArgumentParser]g; | 
| 99 | 164 |  |  |  |  | 570 | push @filters, [$filter, \@args]; | 
| 100 |  |  |  |  |  |  | } | 
| 101 | 295 |  |  |  |  | 1946 | push @{$s->{'nodelist'}}, | 
| 102 |  |  |  |  |  |  | Template::Liquid::Variable->new( | 
| 103 |  |  |  |  |  |  | {template => $s->{template}, | 
| 104 | 295 |  |  |  |  | 495 | parent   => $s, | 
| 105 |  |  |  |  |  |  | markup   => $token, | 
| 106 |  |  |  |  |  |  | variable => $variable, | 
| 107 |  |  |  |  |  |  | filters  => \@filters | 
| 108 |  |  |  |  |  |  | } | 
| 109 |  |  |  |  |  |  | ); | 
| 110 |  |  |  |  |  |  | } | 
| 111 |  |  |  |  |  |  | else { | 
| 112 | 1146 |  |  |  |  | 1897 | push @{$s->{'nodelist'}}, $token; | 
|  | 1146 |  |  |  |  | 3064 |  | 
| 113 |  |  |  |  |  |  | } | 
| 114 |  |  |  |  |  |  | {    # Move the cursor | 
| 115 | 1851 |  |  |  |  | 2874 | my $x  = ($token =~ m[(\n)]g); | 
|  | 1851 |  |  |  |  | 5416 |  | 
| 116 | 1851 |  |  |  |  | 3676 | my $nl = $token =~ tr/\n//; | 
| 117 | 1851 |  |  |  |  | 3232 | $s->{template}{line} += $nl; | 
| 118 |  |  |  |  |  |  | $s->{template}{column} = $nl | 
| 119 |  |  |  |  |  |  | ? rindex $token, "\n" | 
| 120 | 1851 | 100 |  |  |  | 5196 | : $s->{template}{column} + length $token; | 
| 121 |  |  |  |  |  |  | } | 
| 122 |  |  |  |  |  |  | } | 
| 123 | 608 |  |  |  |  | 2353 | return $s; | 
| 124 |  |  |  |  |  |  | } | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | sub render { | 
| 127 | 490 |  |  | 490 | 0 | 977 | my ($s) = @_; | 
| 128 | 490 |  |  |  |  | 857 | my $return = ''; | 
| 129 |  |  |  |  |  |  |  | 
| 130 |  |  |  |  |  |  | #    print STDERR "DEBUG RENDERING NODE\n"; | 
| 131 | 490 |  |  |  |  | 748 | for my $node (@{$s->{'nodelist'}}) { | 
|  | 490 |  |  |  |  | 1168 |  | 
| 132 | 1347 | 100 |  |  |  | 3305 | my $rendering = ref $node ? $node->render() : $node; | 
| 133 | 1347 | 100 |  |  |  | 4153 | $return .= defined $rendering ? $rendering : ''; | 
| 134 |  |  |  |  |  |  | } | 
| 135 | 490 |  |  |  |  | 1342 | return $return; | 
| 136 |  |  |  |  |  |  | } | 
| 137 | 0 |  | 0 | 0 | 0 |  | sub conditional_tag { return $_[0]->{'conditional_tag'} || undef; } | 
| 138 |  |  |  |  |  |  | 1; | 
| 139 |  |  |  |  |  |  |  | 
| 140 |  |  |  |  |  |  | =pod | 
| 141 |  |  |  |  |  |  |  | 
| 142 |  |  |  |  |  |  | =encoding UTF-8 | 
| 143 |  |  |  |  |  |  |  | 
| 144 |  |  |  |  |  |  | =begin stopwords | 
| 145 |  |  |  |  |  |  |  | 
| 146 |  |  |  |  |  |  | Lütke jadedPixel | 
| 147 |  |  |  |  |  |  |  | 
| 148 |  |  |  |  |  |  | =end stopwords | 
| 149 |  |  |  |  |  |  |  | 
| 150 |  |  |  |  |  |  | =head1 NAME | 
| 151 |  |  |  |  |  |  |  | 
| 152 |  |  |  |  |  |  | Template::Liquid::Document - Generic Top-level Object | 
| 153 |  |  |  |  |  |  |  | 
| 154 |  |  |  |  |  |  | =head1 Description | 
| 155 |  |  |  |  |  |  |  | 
| 156 |  |  |  |  |  |  | This shouldn't be used. ...unless you're really interested in how things work. | 
| 157 |  |  |  |  |  |  | This is the grandfather class; everything is a child or subclass of this | 
| 158 |  |  |  |  |  |  | object. | 
| 159 |  |  |  |  |  |  |  | 
| 160 |  |  |  |  |  |  | =head1 Author | 
| 161 |  |  |  |  |  |  |  | 
| 162 |  |  |  |  |  |  | Sanko Robinson <sanko@cpan.org> - http://sankorobinson.com/ | 
| 163 |  |  |  |  |  |  |  | 
| 164 |  |  |  |  |  |  | The original Liquid template system was developed by jadedPixel | 
| 165 |  |  |  |  |  |  | (http://jadedpixel.com/) and Tobias Lütke (http://blog.leetsoft.com/). | 
| 166 |  |  |  |  |  |  |  | 
| 167 |  |  |  |  |  |  | =head1 License and Legal | 
| 168 |  |  |  |  |  |  |  | 
| 169 |  |  |  |  |  |  | Copyright (C) 2009-2022 by Sanko Robinson E<lt>sanko@cpan.orgE<gt> | 
| 170 |  |  |  |  |  |  |  | 
| 171 |  |  |  |  |  |  | This program is free software; you can redistribute it and/or modify it under | 
| 172 |  |  |  |  |  |  | the terms of The Artistic License 2.0.  See the F<LICENSE> file included with | 
| 173 |  |  |  |  |  |  | this distribution or http://www.perlfoundation.org/artistic_license_2_0.  For | 
| 174 |  |  |  |  |  |  | clarification, see http://www.perlfoundation.org/artistic_2_0_notes. | 
| 175 |  |  |  |  |  |  |  | 
| 176 |  |  |  |  |  |  | When separated from the distribution, all original POD documentation is covered | 
| 177 |  |  |  |  |  |  | by the Creative Commons Attribution-Share Alike 3.0 License.  See | 
| 178 |  |  |  |  |  |  | http://creativecommons.org/licenses/by-sa/3.0/us/legalcode.  For clarification, | 
| 179 |  |  |  |  |  |  | see http://creativecommons.org/licenses/by-sa/3.0/us/. | 
| 180 |  |  |  |  |  |  |  | 
| 181 |  |  |  |  |  |  | =cut |