| 1 | package Template::Liquid::Document; | ||||||||||||||||||||
| 2 | 25 | our $VERSION = '1.0.23'; | |||||||||||||||||||
| 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 | ▶ | use Template::Liquid::Variable; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 25 | ▶ | use Template::Liquid::Utility; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | # | ||||||||||||||||||||
| 8 | 369 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||
| 9 | 369 | my ($class, $args) = @_; | |||||||||||||||||||
| 10 | raise Template::Liquid::Error {type => 'Context', | ||||||||||||||||||||
| 11 | template => (), | ||||||||||||||||||||
| 12 | message => 'Missing template argument', | ||||||||||||||||||||
| 13 | fatal => 1 | ||||||||||||||||||||
| 14 | } | ||||||||||||||||||||
| 15 | 369 | ▶ | if !defined $args->{'template'}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 16 | return | ||||||||||||||||||||
| 17 | bless {template => $args->{'template'}, | ||||||||||||||||||||
| 18 | 369 | parent => $args->{'template'} | |||||||||||||||||||
| 19 | }, $class; | ||||||||||||||||||||
| 20 | } | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 608 | ▶ | sub parse { | ||||||||||||||||||
|
Subroutine
parse: called CC=18 SCAR=29.0
Pod
undocumented
| |||||||||||||||||||||
| 23 | 608 | my ($class, $args, $tokens); | |||||||||||||||||||
| 24 | 608 | ▶ | (scalar @_ == 3 ? ($class, $args, $tokens) : ($class, $tokens)) = @_; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 25 | 608 | ▶ | my $s = ref $class ? $class : $class->new($args); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 26 | 608 | my %_tags = $s->{template}->tags; | |||||||||||||||||||
| 27 | 608 | ▶ | NODE: while (defined(my $token = shift @{$tokens})) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 28 | 2090 | ▶ | if ($token =~ $Template::Liquid::Utility::TagMatch) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 29 | 649 | my ($tag, $attrs) = (split ' ', $1, 2); | |||||||||||||||||||
| 30 | 649 | my $package = $_tags{$tag}; | |||||||||||||||||||
| 31 | 649 | ▶ | my $call = $package ? $package->can('new') : (); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | 649 | ▶ | if (defined $call) { | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 33 | my $_tag = $call->($package, | ||||||||||||||||||||
| 34 | {template => $s->{template}, | ||||||||||||||||||||
| 35 | 347 | parent => $s, | |||||||||||||||||||
| 36 | tag_name => $tag, | ||||||||||||||||||||
| 37 | markup => $token, | ||||||||||||||||||||
| 38 | attrs => $attrs | ||||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||
| 41 | 347 | push @{$s->{'nodelist'}}, $_tag; | |||||||||||||||||||
| 42 | 347 | ▶ | if ($_tag->conditional_tag) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 43 | 213 | push @{$_tag->{'blocks'}}, | |||||||||||||||||||
| 44 | Template::Liquid::Block->new( | ||||||||||||||||||||
| 45 | {tag_name => $tag, | ||||||||||||||||||||
| 46 | attrs => $attrs, | ||||||||||||||||||||
| 47 | template => $_tag->{template}, | ||||||||||||||||||||
| 48 | 213 | parent => $_tag | |||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||
| 51 | 213 | $_tag->parse($tokens); | |||||||||||||||||||
| 52 | { # finish previous block | ||||||||||||||||||||
| 53 | 213 | ${$_tag->{'blocks'}[-1]}{'nodelist'} | |||||||||||||||||||
| 54 | 213 | = $_tag->{'nodelist'}; | |||||||||||||||||||
| 55 | 213 | $_tag->{'nodelist'} = []; | |||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | elsif ($_tag->end_tag) { | ||||||||||||||||||||
| 59 | 26 | $_tag->parse($tokens); | |||||||||||||||||||
| 60 | } | ||||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | ▶ | elsif ($s->can('end_tag') && $tag =~ $s->end_tag) { | |||||||||||||||||||
|
Condition66%2/3
$s->can("end_tag") and $tag =~ $s->end_tag
MC/DC50%1/2
$s->can("end_tag") and $tag =~ $s->end_tag
$s->can("end_tag")
$tag =~ $s->end_tag
Truth table66%2/3
A and B
A= $s->can("end_tag")B= $tag =~ $s->end_tag
| |||||||||||||||||||||
| 63 | 239 | $s->{'markup_2'} = $token; | |||||||||||||||||||
| 64 | 239 | last NODE; | |||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | ▶ | elsif ($s->conditional_tag && $tag =~ $s->conditional_tag) { | |||||||||||||||||||
|
Condition33%1/3
$s->conditional_tag and $tag =~ $s->conditional_tag
MC/DC0%0/2
$s->conditional_tag and $tag =~ $s->conditional_tag
$s->conditional_tag
$tag =~ $s->conditional_tag
Truth table33%1/3
A and B
A= $s->conditional_tagB= $tag =~ $s->conditional_tag
| |||||||||||||||||||||
| 67 | $s->push_block({tag_name => $tag, | ||||||||||||||||||||
| 68 | attrs => $attrs, | ||||||||||||||||||||
| 69 | markup => $token, | ||||||||||||||||||||
| 70 | template => $s->{template}, | ||||||||||||||||||||
| 71 | 63 | parent => $s | |||||||||||||||||||
| 72 | }, | ||||||||||||||||||||
| 73 | $tokens | ||||||||||||||||||||
| 74 | ); | ||||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | else { | ||||||||||||||||||||
| 77 | raise Template::Liquid::Error { | ||||||||||||||||||||
| 78 | type => 'Syntax', | ||||||||||||||||||||
| 79 | template => $s->{template}, | ||||||||||||||||||||
| 80 | 0 | message => 'Unknown tag: ' . $token | |||||||||||||||||||
| 81 | }; | ||||||||||||||||||||
| 82 | } | ||||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | elsif ($token =~ $Template::Liquid::Utility::VarMatch) { | ||||||||||||||||||||
| 85 | 295 | my ($variable, $filters) = split qr[\s*\|\s*]o, $1, 2; | |||||||||||||||||||
| 86 | 295 | my @filters; | |||||||||||||||||||
| 87 | 295 | ▶ | for my $filter (split $Template::Liquid::Utility::FilterSeparator, | ||||||||||||||||||
|
Condition100%2/2
$filters || ''
MC/DC100%1/1
$filters || ''
$filters
Truth table100%2/2
A
A= $filters
| |||||||||||||||||||||
| 88 | $filters || '') { | ||||||||||||||||||||
| 89 | 164 | my ($filter, $args) | |||||||||||||||||||
| 90 | = split | ||||||||||||||||||||
| 91 | $Template::Liquid::Utility::FilterArgumentSeparator, | ||||||||||||||||||||
| 92 | $filter, 2; | ||||||||||||||||||||
| 93 | 164 | $filter =~ s[\s*$][]o; # XXX - the splitter should clean... | |||||||||||||||||||
| 94 | 164 | $filter =~ s[^\s*][]o; # XXX - ...this up for us. | |||||||||||||||||||
| 95 | my @args | ||||||||||||||||||||
| 96 | 164 | ▶ | = !defined $args ? () : grep { defined $_ } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 97 | $args | ||||||||||||||||||||
| 98 | =~ m[$Template::Liquid::Utility::VariableFilterArgumentParser]g; | ||||||||||||||||||||
| 99 | 164 | push @filters, [$filter, \@args]; | |||||||||||||||||||
| 100 | } | ||||||||||||||||||||
| 101 | 295 | push @{$s->{'nodelist'}}, | |||||||||||||||||||
| 102 | Template::Liquid::Variable->new( | ||||||||||||||||||||
| 103 | {template => $s->{template}, | ||||||||||||||||||||
| 104 | 295 | parent => $s, | |||||||||||||||||||
| 105 | markup => $token, | ||||||||||||||||||||
| 106 | variable => $variable, | ||||||||||||||||||||
| 107 | filters => \@filters | ||||||||||||||||||||
| 108 | } | ||||||||||||||||||||
| 109 | ); | ||||||||||||||||||||
| 110 | } | ||||||||||||||||||||
| 111 | else { | ||||||||||||||||||||
| 112 | 1146 | push @{$s->{'nodelist'}}, $token; | |||||||||||||||||||
| 113 | } | ||||||||||||||||||||
| 114 | { # Move the cursor | ||||||||||||||||||||
| 115 | 1851 | my $x = ($token =~ m[(\n)]g); | |||||||||||||||||||
| 116 | 1851 | my $nl = $token =~ tr/\n//; | |||||||||||||||||||
| 117 | 1851 | $s->{template}{line} += $nl; | |||||||||||||||||||
| 118 | $s->{template}{column} = $nl | ||||||||||||||||||||
| 119 | ? rindex $token, "\n" | ||||||||||||||||||||
| 120 | 1851 | ▶ | : $s->{template}{column} + length $token; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 121 | } | ||||||||||||||||||||
| 122 | } | ||||||||||||||||||||
| 123 | 608 | return $s; | |||||||||||||||||||
| 124 | } | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | 490 | ▶ | sub render { | ||||||||||||||||||
|
Subroutine
render: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||
| 127 | 490 | my ($s) = @_; | |||||||||||||||||||
| 128 | 490 | my $return = ''; | |||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | # print STDERR "DEBUG RENDERING NODE\n"; | ||||||||||||||||||||
| 131 | 490 | for my $node (@{$s->{'nodelist'}}) { | |||||||||||||||||||
| 132 | 1347 | ▶ | my $rendering = ref $node ? $node->render() : $node; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 133 | 1347 | ▶ | $return .= defined $rendering ? $rendering : ''; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 134 | } | ||||||||||||||||||||
| 135 | 490 | return $return; | |||||||||||||||||||
| 136 | } | ||||||||||||||||||||
| 137 | 0 | ▶ | sub conditional_tag { return $_[0]->{'conditional_tag'} || undef; } | ||||||||||||||||||
|
Subroutine
conditional_tag: not called CC=2 SCAR=17.9
Pod
undocumented
Condition0%0/2
$_[0]{'conditional_tag'} || undef
MC/DC0%0/1
$_[0]{'conditional_tag'} || undef
$_[0]{'conditional_tag'}
Truth table0%0/2
A
A= $_[0]{'conditional_tag'}
| |||||||||||||||||||||
| 138 | 25 | 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 | ||||||||||||||||||||