Liquid/Tag/Capture.pm

filter: Statementstmt 96.7% 30 / 31 Branchbran 58.3% 7 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 2 totaltotal 82.6% 43 / 52 CC 8 SCAR 12.7
CC
8
Cov
86%
new
5.8
render
4.0
BEGIN
1.0
CRAP 3.6
« Liquid/Tag/Unless.pm ↑ Summary Liquid/Tag/If.pm »
1 package Template::Liquid::Tag::Capture;
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 require Template::Liquid::Error;
6 25 require Template::Liquid::Utility;
7 25 ▶BEGIN { use base 'Template::Liquid::Tag'; }
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: not called CC=1 SCAR=0.0
8 25 ▶sub import { Template::Liquid::register_tag('capture') }
Subroutine import: called CC=1 SCAR=0.0
9  
10 11 ▶sub new {
Subroutine new: called CC=5 SCAR=17.5
Pod undocumented
11 11 my ($class, $args) = @_;
12 raise Template::Liquid::Error {type => 'Context',
13 template => $args->{template},
14 message => 'Missing template argument',
15 fatal => 1
16 }
17 11 ▶ if !defined $args->{'template'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args->{"template"} 0 11 11
18 raise Template::Liquid::Error {type => 'Context',
19 template => $args->{template},
20 message => 'Missing parent argument',
21 fatal => 1
22 }
23 11 ▶ if !defined $args->{'parent'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args->{"parent"} 0 11 11
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 11 ▶ if !defined $args->{'attrs'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args->{"attrs"} 0 11 11
31 11 ▶ if ($args->{'attrs'} !~ qr[^(\S+)\s*?$]o) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args->{"attrs"} =~ qr/^(\S+)\s*?$/o) 0 11 11
32 raise Template::Liquid::Error {
33 type => 'Syntax',
34 template => $args->{template},
35 0 message => 'Bad argument list in ' . $args->{'markup'},
36 fatal => 1
37 };
38 }
39 my $s = bless {name => 'c-' . $1,
40 nodelist => [],
41 tag_name => $args->{'tag_name'},
42 variable_name => $1,
43 end_tag => 'end' . $args->{'tag_name'},
44 template => $args->{'template'},
45 parent => $args->{'parent'},
46 11 markup => $args->{'markup'},
47 }, $class;
48 11 return $s;
49 }
50  
51 13 ▶sub render {
Subroutine render: called CC=4 SCAR=13.9
Pod undocumented
52 13 my ($s) = @_;
53 13 my $var = $s->{'variable_name'};
54 13 my $val = '';
55 13 for my $node (@{$s->{'nodelist'}}) {
56 29 ▶ my $rendering = ref $node ? $node->render() : $node;
Branch: 1 branch
BranchTrueFalseTotal
ref $node ? : 8 21 29
57 29 ▶ $val .= defined $rendering ? $rendering : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $rendering ? : 29 0 29
58 }
59 13 $s->{template}{context}->set($var, $val);
60 13 return '';
61 }
62 25 1;
63  
64 =pod
65  
66 =encoding UTF-8
67  
68 =begin stopwords
69  
70 Lütke jadedPixel
71  
72 =end stopwords
73  
74 =head1 NAME
75  
76 Template::Liquid::Tag::Capture - Extended variable assignment construct
77  
78 =head1 Synopsis
79  
80 {% capture triple_x %}
81 {% for x in (1..3) %}{{ x }}{% endfor %}
82 {% endcapture %}
83  
84 =head1 Description
85  
86 If you want to combine a number of strings into a single string and save it to
87 a variable, you can do that with the C<capture> tag. This tag is a block which
88 "captures" whatever is rendered inside it, then assigns the captured value to
89 the given variable instead of rendering it to the screen.
90  
91 =head1 See Also
92  
93 The L<assign|Template::Liquid::Tag::Assign> tag.
94  
95 Liquid for Designers: http://wiki.github.com/tobi/liquid/liquid-for-designers
96  
97 L<Template::Liquid|Template::Liquid/"Create your own filters">'s docs on custom
98 filter creation
99  
100 =head1 Author
101  
102 Sanko Robinson <sanko@cpan.org> - http://sankorobinson.com/
103  
104 The original Liquid template system was developed by jadedPixel
105 (http://jadedpixel.com/) and Tobias Lütke (http://blog.leetsoft.com/).
106  
107 =head1 License and Legal
108  
109 Copyright (C) 2009-2022 by Sanko Robinson E<lt>sanko@cpan.orgE<gt>
110  
111 This program is free software; you can redistribute it and/or modify it under
112 the terms of The Artistic License 2.0. See the F<LICENSE> file included with
113 this distribution or http://www.perlfoundation.org/artistic_license_2_0. For
114 clarification, see http://www.perlfoundation.org/artistic_2_0_notes.
115  
116 When separated from the distribution, all original POD documentation is covered
117 by the Creative Commons Attribution-Share Alike 3.0 License. See
118 http://creativecommons.org/licenses/by-sa/3.0/us/legalcode. For clarification,
119 see http://creativecommons.org/licenses/by-sa/3.0/us/.
120  
121 =cut
« Liquid/Tag/Unless.pm ↑ Summary Liquid/Tag/If.pm »