blib/lib/Template/Liquid/Tag/Assign.pm

filter: Statementstmt 98.0% 50 / 51 Branchbran 68.7% 11 / 16 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 2 totaltotal 83.9% 68 / 81 CC 12 SCAR 16.3
CC
12
Cov
89%
new
7.1
render
6.2
BEGIN
1.0
CRAP 5.1
« blib/lib/Template/Liquid/Variable.pm ↑ Summary blib/lib/Template/Liquid/Block.pm »
1 package Template::Liquid::Tag::Assign;
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 require Template::Liquid::Error;
6 24 require Template::Liquid::Utility;
7 24 ▶BEGIN { use base 'Template::Liquid::Tag'; }
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: not called CC=1 SCAR=0.0
8 24 ▶sub import { Template::Liquid::register_tag('assign') }
Subroutine import: called CC=1 SCAR=0.0
9  
10 sub new {
11 63 ▶ my ($class, $args) = @_;
Subroutine new: called CC=7 SCAR=19.6
Pod undocumented
12 raise Template::Liquid::Error {type => 'Context',
13 template => $args->{template},
14 message => 'Missing template argument',
15 fatal => 1
16 }
17 63 ▶ if !defined $args->{'template'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args->{"template"} 0 63 63
18 raise Template::Liquid::Error {type => 'Context',
19 template => $args->{template},
20 message => 'Missing parent argument',
21 fatal => 1
22 }
23 63 ▶ if !defined $args->{'parent'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args->{"parent"} 0 63 63
24 raise Template::Liquid::Error {
25 type => 'Syntax',
26 template => $args->{template},
27 message => 'Missing argument list in ' . $args->{'markup'},
28 fatal => 1
29 }
30 63 ▶ if !defined $args->{'attrs'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args->{"attrs"} 0 63 63
31 ($args->{'variable'}, $args->{'value'}, my $filters)
32 63 = split m[\s*[=\|]\s+?]o, $args->{'attrs'}, 3;
33 63 $args->{'name'} = 'a-' . $args->{'attrs'};
34 63 $args->{'filters'} = [];
35 63 ▶ if ($filters) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filters) 27 36 63
36 27 for my $filter (split $Template::Liquid::Utility::FilterSeparator,
37 $filters) {
38 30 my ($filter, $f_args)
39 = split $Template::Liquid::Utility::FilterArgumentSeparator,
40 $filter, 2;
41 30 $filter =~ s[\s*$][]o; # XXX - the splitter should clean...
42 30 $filter =~ s[^\s*][]o; # XXX - ...this up for us.
43 my @f_args
44 30 ▶ = !defined $f_args ? () : grep { defined $_ }
Branch: 1 branch
BranchTrueFalseTotal
!defined($f_args) ? : 3 27 30
45 $f_args
46 =~ m[$Template::Liquid::Utility::VariableFilterArgumentParser]g;
47 30 push @{$args->{'filters'}}, [$filter, \@f_args];
48 }
49 }
50 63 return bless $args, $class;
51 }
52  
53 sub render {
54 63 ▶ my $s = shift;
Subroutine render: called CC=6 SCAR=18.2
Pod undocumented
55 63 my $var = $s->{'variable'};
56 63 my $val = $s->{template}{context}->get($s->{'value'});
57 { # XXX - Duplicated in Template::Liquid::Variable::render
58 63 ▶ if (scalar @{$s->{filters}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$s->{"filters"};}) 27 36 63
59 27 my %_filters = $s->{template}->filters;
60 27 FILTER: for my $filter (@{$s->{filters}}) {
61 30 my ($name, $args) = @$filter;
62 30 ▶ map { $_ = $s->{template}{context}->get($_) || $_ } @$args;
Condition33%1/3
$s->{'template'}{'context'}->get($_) || $_
l!l&&r!l&&!r
2900
MC/DC0%0/2
$s->{'template'}{'context'}->get($_) || $_
$s->{'template'}{'context'}->get($_) $_
Truth table33%1/3
A || B
A= $s->{'template'}{'context'}->get($_)B= $_
ABresult
1X1
011
000
63 30 my $package = $_filters{$name};
64 30 ▶ my $call = $package ? $package->can($name) : ();
Branch: 1 branch
BranchTrueFalseTotal
$package ? : 30 0 30
65 30 ▶ if ($call) {
Branch: 1 branch
BranchTrueFalseTotal
if ($call) 30 0 30
66 30 $val = $call->($val, @$args);
67 30 next FILTER;
68 }
69 raise Template::Liquid::Error {
70 template => $s->{template},
71 0 type => 'Filter',
72 message => "Filter '$name' not found",
73 fatal => 1
74 };
75 }
76 }
77 }
78 63 $s->{template}{context}->set($var, $val);
79 63 return '';
80 }
81 24 1;
82  
83 =pod
84  
85 =encoding UTF-8
86  
87 =begin stopwords
88  
89 Lütke jadedPixel
90  
91 =end stopwords
92  
93 =head1 NAME
94  
95 Template::Liquid::Tag::Assign - Variable assignment construct
96  
97 =head1 Synopsis
98  
99 {% assign some.variable = 'this value' %}
100  
101 =head1 Description
102  
103 You can store data in your own variables for later use as output or in other
104 tags. The simplest way to create a variable is with the C<assign> tag which a
105 rather straightforward syntax.
106  
107 {% assign person.name = 'john' %}
108 Hello, {{ person.name | capitalize }}.
109  
110 You can modify the value C<before> assignment with
111 L<filters|Template::Liquid::Filters>.
112  
113 {% assign person.name = 'john' | capitalize %}
114 Hello, {{ person.name }}.
115  
116 =head1 See Also
117  
118 Liquid for Designers: http://wiki.github.com/tobi/liquid/liquid-for-designers
119  
120 L<Template::Liquid|Template::Liquid/"Create your own filters">'s docs on custom
121 filter creation
122  
123 =head1 Author
124  
125 Sanko Robinson <sanko@cpan.org> - http://sankorobinson.com/
126  
127 The original Liquid template system was developed by jadedPixel
128 (http://jadedpixel.com/) and Tobias Lütke (http://blog.leetsoft.com/).
129  
130 =head1 License and Legal
131  
132 Copyright (C) 2009-2022 by Sanko Robinson E<lt>sanko@cpan.orgE<gt>
133  
134 This program is free software; you can redistribute it and/or modify it under
135 the terms of The Artistic License 2.0. See the F<LICENSE> file included with
136 this distribution or http://www.perlfoundation.org/artistic_license_2_0. For
137 clarification, see http://www.perlfoundation.org/artistic_2_0_notes.
138  
139 When separated from the distribution, all original POD documentation is covered
140 by the Creative Commons Attribution-Share Alike 3.0 License. See
141 http://creativecommons.org/licenses/by-sa/3.0/us/legalcode. For clarification,
142 see http://creativecommons.org/licenses/by-sa/3.0/us/.
143  
144 =cut
« blib/lib/Template/Liquid/Variable.pm ↑ Summary blib/lib/Template/Liquid/Block.pm »