| 1 | package Template::Liquid::Variable; | ||||||||||||||||||||||||||||
| 2 | 24 | our $VERSION = '1.0.22'; | |||||||||||||||||||||||||||
| 3 | 24 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 24 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 24 | ▶ | use base 'Template::Liquid::Document'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 24 | ▶ | use Template::Liquid::Error; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | sub new { | ||||||||||||||||||||||||||||
| 9 | 293 | ▶ | my ($class, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=18.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 10 | raise Template::Liquid::Error {type => 'Context', | ||||||||||||||||||||||||||||
| 11 | template => $args->{template}, | ||||||||||||||||||||||||||||
| 12 | message => 'Missing template argument', | ||||||||||||||||||||||||||||
| 13 | fatal => 1 | ||||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||
| 15 | if !defined $args->{'template'} || | ||||||||||||||||||||||||||||
| 16 | 293 | ▶ | !$args->{'template'}->isa('Template::Liquid'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $args->{"template"} and $args->{"template"}->isa("Template::Liquid")
MC/DC0%0/2
defined $args->{"template"} and $args->{"template"}->isa("Template::Liquid")
defined $args->{"template"}
$args->{"template"}->isa("Template::Liquid")
Truth table33%1/3
A and B
A= defined $args->{"template"}B= $args->{"template"}->isa("Template::Liquid")
| |||||||||||||||||||||||||||||
| 17 | raise Template::Liquid::Error {type => 'Context', | ||||||||||||||||||||||||||||
| 18 | template => $args->{template}, | ||||||||||||||||||||||||||||
| 19 | message => 'Missing parent argument', | ||||||||||||||||||||||||||||
| 20 | fatal => 1 | ||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | 293 | ▶ | if !defined $args->{'parent'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | raise Template::Liquid::Error { | ||||||||||||||||||||||||||||
| 24 | template => $args->{template}, | ||||||||||||||||||||||||||||
| 25 | type => 'Syntax', | ||||||||||||||||||||||||||||
| 26 | message => 'Missing variable name in ' . $args->{'markup'}, | ||||||||||||||||||||||||||||
| 27 | fatal => 1 | ||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | 293 | ▶ | if !defined $args->{'variable'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 293 | return bless $args, $class; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | sub render { | ||||||||||||||||||||||||||||
| 34 | 534 | ▶ | my ($s) = @_; | ||||||||||||||||||||||||||
|
Subroutine
render: called CC=7 SCAR=19.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 35 | 534 | my $val = $s->{template}{context}->get($s->{variable}); | |||||||||||||||||||||||||||
| 36 | { # XXX - Duplicated in Template::Liquid::Assign::render | ||||||||||||||||||||||||||||
| 37 | 534 | ▶ | if (scalar @{$s->{filters}}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 158 | my %_filters = $s->{template}->filters; | |||||||||||||||||||||||||||
| 39 | 158 | FILTER: for my $filter (@{$s->{filters}}) { | |||||||||||||||||||||||||||
| 40 | 168 | my ($name, $args) = @$filter; | |||||||||||||||||||||||||||
| 41 | 168 | my $package = $_filters{$name}; | |||||||||||||||||||||||||||
| 42 | 168 | ▶ | my $call = $package ? $package->can($name) : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 168 | ▶ | if ($call) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | #use Data::Dump qw[dump]; | ||||||||||||||||||||||||||||
| 46 | #warn sprintf 'Before %s(%s): %s', $name, dump($args), dump($val); | ||||||||||||||||||||||||||||
| 47 | #warn $s->{template}{context}->get($args->[0]) if ref $args; | ||||||||||||||||||||||||||||
| 48 | $val = $call->( | ||||||||||||||||||||||||||||
| 49 | $val, | ||||||||||||||||||||||||||||
| 50 | 168 | map { $s->{template}{context}->get($_); } @$args | |||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | #warn sprintf 'After %s(%s): %s', $name, dump($args), dump($val); | ||||||||||||||||||||||||||||
| 54 | 168 | next FILTER; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | raise Template::Liquid::Error {type => 'UnknownFilter', | ||||||||||||||||||||||||||||
| 57 | template => $s->{template}, | ||||||||||||||||||||||||||||
| 58 | 0 | message => $name, | |||||||||||||||||||||||||||
| 59 | fatal => 0 | ||||||||||||||||||||||||||||
| 60 | }; | ||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | #warn '---> ' . $s->{variable} . ' ===> ' .$val; | ||||||||||||||||||||||||||||
| 66 | 534 | ▶ | return join '', @$val if ref $val eq 'ARRAY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 533 | ▶ | return join '', keys %$val if ref $val eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 533 | return $val; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | 24 | 1; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =pod | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =head1 NAME | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | Template::Liquid::Variable - Generic Value Container | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | =head1 Description | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | This class can hold just about anything. This is the class responsible for | ||||||||||||||||||||||||||||
| 81 | handling echo statements: | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | Hello, {{ name }}. It's been {{ lastseen | date_relative }} since you | ||||||||||||||||||||||||||||
| 84 | logged in. | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | Internally, a variable is the basic container for everything; lists, scalars, | ||||||||||||||||||||||||||||
| 87 | hashes, and even objects. | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | L<Filters|Template::Liquid::Filters> are applied to variables during the render | ||||||||||||||||||||||||||||
| 90 | stage. | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =head1 Author | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | Sanko Robinson <sanko@cpan.org> - http://sankorobinson.com/ | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | CPAN ID: SANKO | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =head1 License and Legal | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | Copyright (C) 2009-2022 by Sanko Robinson E<lt>sanko@cpan.orgE<gt> | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | This program is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 103 | the terms of L<The Artistic License | ||||||||||||||||||||||||||||
| 104 | 2.0|http://www.perlfoundation.org/artistic_license_2_0>. See the F<LICENSE> | ||||||||||||||||||||||||||||
| 105 | file included with this distribution or L<notes on the Artistic License | ||||||||||||||||||||||||||||
| 106 | 2.0|http://www.perlfoundation.org/artistic_2_0_notes> for clarification. | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | When separated from the distribution, all original POD documentation is covered | ||||||||||||||||||||||||||||
| 109 | by the L<Creative Commons Attribution-Share Alike 3.0 | ||||||||||||||||||||||||||||
| 110 | License|http://creativecommons.org/licenses/by-sa/3.0/us/legalcode>. See the | ||||||||||||||||||||||||||||
| 111 | L<clarification of the | ||||||||||||||||||||||||||||
| 112 | CCA-SA3.0|http://creativecommons.org/licenses/by-sa/3.0/us/>. | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =cut | ||||||||||||||||||||||||||||