| 1 | package Template::Liquid::Block; | ||||||||||||||||||||||||||||
| 2 | 25 | our $VERSION = '1.0.23'; | |||||||||||||||||||||||||||
| 3 | 25 | require Template::Liquid::Error; | |||||||||||||||||||||||||||
| 4 | 25 | ▶ | use base 'Template::Liquid::Document'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 25 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 25 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 276 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=18.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 9 | 276 | my ($class, $args) = @_; | |||||||||||||||||||||||||||
| 10 | raise Template::Liquid::Error {type => 'Context', | ||||||||||||||||||||||||||||
| 11 | template => $args->{template}, | ||||||||||||||||||||||||||||
| 12 | message => 'Missing template argument', | ||||||||||||||||||||||||||||
| 13 | fatal => 1 | ||||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||
| 15 | 276 | ▶ | if !defined $args->{'template'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | raise Template::Liquid::Error {type => 'Context', | ||||||||||||||||||||||||||||
| 17 | template => $args->{template}, | ||||||||||||||||||||||||||||
| 18 | message => 'Missing parent argument', | ||||||||||||||||||||||||||||
| 19 | fatal => 1 | ||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | 276 | ▶ | if !defined $args->{'parent'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | raise Template::Liquid::Error { | ||||||||||||||||||||||||||||
| 23 | template => $args->{template}, | ||||||||||||||||||||||||||||
| 24 | type => 'Syntax', | ||||||||||||||||||||||||||||
| 25 | message => 'else tags are non-conditional: ' . $args->{'markup'}, | ||||||||||||||||||||||||||||
| 26 | fatal => 1 | ||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | 276 | ▶ | if $args->{'tag_name'} eq 'else' && $args->{'attrs'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$args->{"tag_name"} eq "else" and $args->{"attrs"}
MC/DC0%0/2
$args->{"tag_name"} eq "else" and $args->{"attrs"}
$args->{"tag_name"} eq "else"
$args->{"attrs"}
Truth table66%2/3
A and B
A= $args->{"tag_name"} eq "else"B= $args->{"attrs"}
| |||||||||||||||||||||||||||||
| 29 | my $s = bless {tag_name => 'b-' . $args->{'tag_name'}, | ||||||||||||||||||||||||||||
| 30 | conditions => undef, | ||||||||||||||||||||||||||||
| 31 | nodelist => [], | ||||||||||||||||||||||||||||
| 32 | template => $args->{'template'}, | ||||||||||||||||||||||||||||
| 33 | 276 | parent => $args->{'parent'}, | |||||||||||||||||||||||||||
| 34 | }, $class; | ||||||||||||||||||||||||||||
| 35 | $s->{'conditions'} = ( | ||||||||||||||||||||||||||||
| 36 | 252 | ▶ | $args->{'tag_name'} eq 'else' ? [1] : sub { # Oh, what a mess... | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 37 | my @conditions | ||||||||||||||||||||||||||||
| 38 | = split | ||||||||||||||||||||||||||||
| 39 | m/(?:\s+\b(and|or)\b\s+)(?![^"]*"(?:[^"]*"[^"]*")*[^"]*$)/o, | ||||||||||||||||||||||||||||
| 40 | $args->{parent}->{tag_name} eq 'for' | ||||||||||||||||||||||||||||
| 41 | ? 1 | ||||||||||||||||||||||||||||
| 42 | 252 | ▶ | : (defined $args->{'attrs'} ? $args->{'attrs'} : ''); | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 43 | 252 | my @equality; | |||||||||||||||||||||||||||
| 44 | 252 | ▶ | while (my $x = shift @conditions) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | push @equality, | ||||||||||||||||||||||||||||
| 46 | ( | ||||||||||||||||||||||||||||
| 47 | $x | ||||||||||||||||||||||||||||
| 48 | =~ m/(?:\b(and|or)\b)(?![^"]*"(?:[^"]*"[^"]*")*[^"]*$)/o | ||||||||||||||||||||||||||||
| 49 | ? bless({template => $args->{'template'}, | ||||||||||||||||||||||||||||
| 50 | parent => $s, | ||||||||||||||||||||||||||||
| 51 | condition => $x, | ||||||||||||||||||||||||||||
| 52 | lvalue => pop @equality, | ||||||||||||||||||||||||||||
| 53 | rvalue => | ||||||||||||||||||||||||||||
| 54 | Template::Liquid::Condition->new( | ||||||||||||||||||||||||||||
| 55 | {template => $args->{'template'}, | ||||||||||||||||||||||||||||
| 56 | parent => $s, | ||||||||||||||||||||||||||||
| 57 | attrs => shift @conditions | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | ) | ||||||||||||||||||||||||||||
| 60 | }, | ||||||||||||||||||||||||||||
| 61 | 'Template::Liquid::Condition' | ||||||||||||||||||||||||||||
| 62 | ) | ||||||||||||||||||||||||||||
| 63 | : Template::Liquid::Condition->new( | ||||||||||||||||||||||||||||
| 64 | {attrs => $x, | ||||||||||||||||||||||||||||
| 65 | 275 | ▶ | template => $args->{'template'}, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | parent => $s, | ||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | ) | ||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | 252 | \@equality; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | 276 | ▶ | ->() | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | ); | ||||||||||||||||||||||||||||
| 75 | 276 | return $s; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | 25 | 1; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =pod | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =begin stopwords | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | sorta whitespace Lütke jadedPixel | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =end stopwords | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | =head1 NAME | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | Template::Liquid::Block - Simple Node Type | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =head1 Description | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | There's not really a lot to say about basic blocks. The real action is in the | ||||||||||||||||||||||||||||
| 96 | classes which make use of them or subclass it. See | ||||||||||||||||||||||||||||
| 97 | L<if|Template::Liquid::Tag::If>, L<unless|Template::Liquid::Tag::Unless>, or | ||||||||||||||||||||||||||||
| 98 | L<case|Template::Liquid::Tag::Case>. | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | =head1 Bugs | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | Liquid's (and by extension L<Template::Liquid|Template::Liquid>'s) treatment of | ||||||||||||||||||||||||||||
| 103 | compound inequalities is broken. For example... | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | {% if 'This and that' contains 'that' and 1 == 3 %} | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | ...would be parsed as if it were... | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | if ( "'This" && ( "that'" =~ m[and] ) ) { ... | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | ...but it should look like... | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | if ( ( 'This and that' =~ m[that]) && ( 1 == 3 ) ) { ... | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | It's just... not pretty but I'll work on it. | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | =head1 See Also | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | See L<Template::Liquid::Condition|Template::Liquid::Condition> for a list of | ||||||||||||||||||||||||||||
| 120 | supported inequalities. | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | =head1 Author | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | Sanko Robinson <sanko@cpan.org> - http://sankorobinson.com/ | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | The original Liquid template system was developed by jadedPixel | ||||||||||||||||||||||||||||
| 127 | (http://jadedpixel.com/) and Tobias Lütke (http://blog.leetsoft.com/). | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | =head1 License and Legal | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | Copyright (C) 2009-2022 by Sanko Robinson E<lt>sanko@cpan.orgE<gt> | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | This program is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 134 | the terms of The Artistic License 2.0. See the F<LICENSE> file included with | ||||||||||||||||||||||||||||
| 135 | this distribution or http://www.perlfoundation.org/artistic_license_2_0. For | ||||||||||||||||||||||||||||
| 136 | clarification, see http://www.perlfoundation.org/artistic_2_0_notes. | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | When separated from the distribution, all original POD documentation is covered | ||||||||||||||||||||||||||||
| 139 | by the Creative Commons Attribution-Share Alike 3.0 License. See | ||||||||||||||||||||||||||||
| 140 | http://creativecommons.org/licenses/by-sa/3.0/us/legalcode. For clarification, | ||||||||||||||||||||||||||||
| 141 | see http://creativecommons.org/licenses/by-sa/3.0/us/. | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | =cut | ||||||||||||||||||||||||||||