| 1 | package Template::Liquid::Condition; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 24 | our $VERSION = '1.0.22'; | |||||||||||||||||||||||||||||||||||||||||||||
| 3 | 24 | require Template::Liquid::Error; | |||||||||||||||||||||||||||||||||||||||||||||
| 4 | 24 | ▶ | use base 'Template::Liquid::Block'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 24 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 24 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # Makes life easy | ||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 24 | ▶ | use overload 'bool' => \&is_true, fallback => 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 265 | ▶ | my ($class, $args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=17 SCAR=31.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | raise Template::Liquid::Error {type => 'Context', | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | template => $args->{template}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | message => 'Missing template argument', | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | fatal => 1 | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 265 | ▶ | if !defined $args->{'template'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | raise Template::Liquid::Error {type => 'Context', | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | template => $args->{template}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | message => 'Missing parent argument', | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | fatal => 1 | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 265 | ▶ | if !defined $args->{'parent'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | my ($lval, $condition, $rval) | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 265 | ▶ | = ((defined $args->{'attrs'} ? $args->{'attrs'} : '') | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | =~ m[("[^"]+"|'[^']+'|(?:[\S]+))]go); | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 265 | ▶ | if (defined $lval) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 265 | ▶ | if (!defined $rval && !defined $condition) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
defined $rval || defined $condition
MC/DC50%1/2
defined $rval || defined $condition
defined $rval
defined $condition
Truth table66%2/3
A || B
A= defined $rvalB= defined $condition
| |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | return | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | bless {lvalue => $lval, | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | condition => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | rvalue => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | template => $args->{'template'}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 127 | parent => $args->{'parent'} | |||||||||||||||||||||||||||||||||||||||||||||
| 36 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | elsif ($condition =~ m[^(?:eq|==|ne|!=|lt|<|gt|>|contains|&&|\|\|)$]o) | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 138 | ▶ | { $condition = 'eq' if $condition eq '=='; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 138 | ▶ | $condition = 'ne' if $condition eq '!='; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 138 | ▶ | $condition = 'gt' if $condition eq '>'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 138 | ▶ | $condition = 'lt' if $condition eq '<'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 138 | ▶ | $condition = '_and' if $condition eq '&&'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 138 | ▶ | $condition = '_and' if $condition eq 'and'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 138 | ▶ | $condition = '_or' if $condition eq '||'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 138 | ▶ | $condition = '_or' if $condition eq 'or'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | return | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | bless {lvalue => $lval, | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | condition => $condition, | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | rvalue => $rval, | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | template => $args->{'template'}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 138 | parent => $args->{'parent'} | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ...; | |||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | raise Template::Liquid::Error { | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | template => $args->{template}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | type => 'Context', | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | message => 'Unknown operator "' . $condition . '" in ' . | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | $lval . ' ' . $condition . ' ' . (defined $rval ? $rval : '') | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | return | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | Template::Liquid::Error->new( | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | template => $args->{template}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | type => 'Context', | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | message => 'Bad conditional statement: ' . $args->{'attrs'} | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 24 | ▶ | sub ne { return !$_[0]->eq } # hashes | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ne: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | sub eq { | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 263 | ▶ | my ($s) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
eq: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 263 | ▶ | my $l = $s->{template}{context}->get($s->{'lvalue'}) || $s->{'lvalue'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$s->{'template'}{'context'}->get($s->{'lvalue'}) || $s->{'lvalue'}
MC/DC0%0/2
$s->{'template'}{'context'}->get($s->{'lvalue'}) || $s->{'lvalue'}
$s->{'template'}{'context'}->get($s->{'lvalue'})
$s->{'lvalue'}
Truth table66%2/3
A || B
A= $s->{'template'}{'context'}->get($s->{'lvalue'})B= $s->{'lvalue'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 263 | ▶ | my $r = $s->{template}{context}->get($s->{'rvalue'}) || $s->{'rvalue'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$s->{'template'}{'context'}->get($s->{'rvalue'}) || $s->{'rvalue'}
MC/DC50%1/2
$s->{'template'}{'context'}->get($s->{'rvalue'}) || $s->{'rvalue'}
$s->{'template'}{'context'}->get($s->{'rvalue'})
$s->{'rvalue'}
Truth table66%2/3
A || B
A= $s->{'template'}{'context'}->get($s->{'rvalue'})B= $s->{'rvalue'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # Might need to render these again | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 263 | my $_l = $s->{template}{context}->get($l); | |||||||||||||||||||||||||||||||||||||||||||||
| 81 | 263 | my $_r = $s->{template}{context}->get($r); | |||||||||||||||||||||||||||||||||||||||||||||
| 82 | 263 | ▶ | $l = $_l if defined $_l; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 263 | ▶ | $r = $_r if defined $_r; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 263 | return _equal($l, $r); | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | sub _equal { # XXX - Pray we don't have a recursive data structure... | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 283 | ▶ | my ($l, $r) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_equal: called CC=15 SCAR=27.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 283 | my $ref_l = ref $l; | |||||||||||||||||||||||||||||||||||||||||||||
| 90 | 283 | ▶ | return !1 if $ref_l ne ref $r; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 281 | ▶ | if (!$ref_l) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | return | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 538 | ▶ | !!(grep {defined} $l, $r) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 269 | ▶ | ? (grep {m[\D]o} $l, $r) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | ? $l eq $r | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | : $l == $r | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | : !1; | ||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | elsif ($ref_l eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 6 | ▶ | return !1 unless scalar @$l == scalar @$r; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 4 | for my $index (0 .. $#{$l}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 102 | 16 | ▶ | return !1 if !_equal($l->[$index], $r->[$index]); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 2 | return !!1; | |||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | elsif ($ref_l eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 6 | my %temp = %$r; | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | 6 | for my $key (keys %$l) { | |||||||||||||||||||||||||||||||||||||||||||||
| 109 | return 0 | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | unless exists $temp{$key} and | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | defined($l->{$key}) eq defined($temp{$key}) and | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 6 | ▶ | (defined $temp{$key} ? _equal($temp{$key}, $l->{$key}) : !!1); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition83%5/6
exists $temp{$key} and defined $l->{$key} eq defined $temp{$key} and
exists $temp{$key} and defined $l->{$key} eq defined $temp{$key}
MC/DC66%2/3
exists $temp{$key} and defined $l->{$key} eq defined $temp{$key} and
exists $temp{$key}
defined $l->{$key} eq defined $temp{$key}
Truth table75%3/4
A and B and C
A= exists $temp{$key}B= defined $l->{$key} eq defined $temp{$key}C=
| |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 2 | delete $temp{$key}; | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 2 | return !keys(%temp); | |||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | sub gt { | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 45 | ▶ | my ($s) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
gt: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | my ($l, $r) | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 90 | ▶ | = map { $s->{template}{context}->get($_) || $_ } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 45 | ($$s{'lvalue'}, $$s{'rvalue'}); | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | # Might need to render these again | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 45 | my $_l = $s->{template}{context}->get($l); | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | 45 | my $_r = $s->{template}{context}->get($r); | |||||||||||||||||||||||||||||||||||||||||||||
| 128 | 45 | ▶ | $l = $_l if defined $_l; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 45 | ▶ | $r = $_r if defined $_r; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | return | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 90 | ▶ | !!(grep {defined} $l, $r) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 45 | ▶ | ? (grep {m[\D]o} $l, $r) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | ? $l gt $r | ||||||||||||||||||||||||||||||||||||||||||||||
| 134 | : $l > $r | ||||||||||||||||||||||||||||||||||||||||||||||
| 135 | : 0; | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 12 | ▶ | sub lt { return !$_[0]->gt } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lt: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | sub contains { | ||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 12 | ▶ | my ($s) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
contains: called CC=10 SCAR=23.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 12 | my $l = $s->{template}{context}->get($s->{'lvalue'}); | |||||||||||||||||||||||||||||||||||||||||||||
| 142 | 12 | my $r = $s->{template}{context}->get($s->{'rvalue'}); | |||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | # Might need to render these again | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 12 | my $_l = $s->{template}{context}->get($l); | |||||||||||||||||||||||||||||||||||||||||||||
| 146 | 12 | my $_r = $s->{template}{context}->get($r); | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | 12 | ▶ | $l = $_l if defined $_l; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 12 | ▶ | $r = $_r if defined $_r; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 12 | $r = quotemeta $r; | |||||||||||||||||||||||||||||||||||||||||||||
| 150 | 12 | ▶ | return if defined $r && !defined $l; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $r and not defined $l
MC/DC0%0/2
defined $r and not defined $l
defined $r
not defined $l
Truth table33%1/3
A and not(B)
A= defined $rB= not defined $l
| |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 12 | ▶ | return defined($l->{$r}) ? 1 : !1 if ref $l eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 8 | ▶ | return (grep { $_ eq $r } @$l) ? 1 : !1 if ref $l eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 4 | ▶ | return $l =~ qr[${r}] ? 1 : !1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | sub _and { | ||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | my ($s) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_and: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | my $l = $s->{template}{context}->get($s->{'lvalue'}) || $s->{'lvalue'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$s->{'template'}{'context'}->get($s->{'lvalue'}) || $s->{'lvalue'}
MC/DC0%0/2
$s->{'template'}{'context'}->get($s->{'lvalue'}) || $s->{'lvalue'}
$s->{'template'}{'context'}->get($s->{'lvalue'})
$s->{'lvalue'}
Truth table0%0/3
A || B
A= $s->{'template'}{'context'}->get($s->{'lvalue'})B= $s->{'lvalue'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | my $r = $s->{template}{context}->get($s->{'rvalue'}) || $s->{'rvalue'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$s->{'template'}{'context'}->get($s->{'rvalue'}) || $s->{'rvalue'}
MC/DC0%0/2
$s->{'template'}{'context'}->get($s->{'rvalue'}) || $s->{'rvalue'}
$s->{'template'}{'context'}->get($s->{'rvalue'})
$s->{'rvalue'}
Truth table0%0/3
A || B
A= $s->{'template'}{'context'}->get($s->{'rvalue'})B= $s->{'rvalue'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | # Might need to render these again | ||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | my $_l = $s->{template}{context}->get($l); | |||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | my $_r = $s->{template}{context}->get($r); | |||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | $l = $_l if defined $_l; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | $r = $_r if defined $_r; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | return !!($l && $r); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$l && $r
MC/DC0%0/2
$l && $r
$l
$r
Truth table0%0/3
A && B
A= $lB= $r
| |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | sub _or { | ||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | my ($s) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_or: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | my $l = $s->{template}{context}->get($s->{'lvalue'}) || $s->{'lvalue'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$s->{'template'}{'context'}->get($s->{'lvalue'}) || $s->{'lvalue'}
MC/DC0%0/2
$s->{'template'}{'context'}->get($s->{'lvalue'}) || $s->{'lvalue'}
$s->{'template'}{'context'}->get($s->{'lvalue'})
$s->{'lvalue'}
Truth table0%0/3
A || B
A= $s->{'template'}{'context'}->get($s->{'lvalue'})B= $s->{'lvalue'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | my $r = $s->{template}{context}->get($s->{'rvalue'}) || $s->{'rvalue'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$s->{'template'}{'context'}->get($s->{'rvalue'}) || $s->{'rvalue'}
MC/DC0%0/2
$s->{'template'}{'context'}->get($s->{'rvalue'}) || $s->{'rvalue'}
$s->{'template'}{'context'}->get($s->{'rvalue'})
$s->{'rvalue'}
Truth table0%0/3
A || B
A= $s->{'template'}{'context'}->get($s->{'rvalue'})B= $s->{'rvalue'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||
| 174 | # Might need to render these again | ||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | my $_l = $s->{template}{context}->get($l); | |||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | my $_r = $s->{template}{context}->get($r); | |||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | $l = $_l if defined $_l; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | ▶ | $r = $_r if defined $_r; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | return !!($l || $r); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$l || $r
MC/DC0%0/2
$l || $r
$l
$r
Truth table0%0/3
A || B
A= $lB= $r
| |||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 181 | { # Compound inequalities support | ||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | sub and { | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 15 | ▶ | my ($s) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
and: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 15 | my $l = $s->{'lvalue'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 186 | 15 | my $r = $s->{'rvalue'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 187 | 15 | ▶ | return !!($l && $r); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$l && $r
MC/DC0%0/2
$l && $r
$l
$r
Truth table33%1/3
A && B
A= $lB= $r
| |||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||
| 190 | sub or { | ||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 43 | ▶ | my ($s) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
or: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 43 | my $l = $s->{'lvalue'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 193 | 43 | my $r = $s->{'rvalue'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 194 | 43 | ▶ | return !!($l || $r); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$l || $r
MC/DC0%0/2
$l || $r
$l
$r
Truth table33%1/3
A || B
A= $lB= $r
| |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 24 | sub is_true { | |||||||||||||||||||||||||||||||||||||||||||||
| 199 | 406 | ▶ | my ($s) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_true: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 406 | ▶ | if (!defined $s->{'condition'} && !defined $s->{'rvalue'}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $s->{"condition"} or defined $s->{"rvalue"}
MC/DC50%1/2
defined $s->{"condition"} or defined $s->{"rvalue"}
defined $s->{"condition"}
defined $s->{"rvalue"}
Truth table66%2/3
A or B
A= defined $s->{"condition"}B= defined $s->{"rvalue"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||
| 202 | # Might need to render these again | ||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 28 | my $l = $s->{template}{context}->get($s->{'lvalue'}); | |||||||||||||||||||||||||||||||||||||||||||||
| 204 | 28 | my $_l = $s->{template}{context}->get($l); | |||||||||||||||||||||||||||||||||||||||||||||
| 205 | 28 | ▶ | $l = $_l if defined $_l; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 28 | ▶ | return !!($l) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 378 | my $condition = $s->can($s->{'condition'}); | |||||||||||||||||||||||||||||||||||||||||||||
| 209 | raise Template::Liquid::Error { | ||||||||||||||||||||||||||||||||||||||||||||||
| 210 | template => $s->{template}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 211 | type => 'Context', | ||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 378 | ▶ | message => 'Bad condition ' . $s->{'condition'}, | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 213 | fatal => 1 | ||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 215 | if !$condition; | ||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||
| 217 | #return !1 if !$condition; | ||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 378 | return $s->$condition(); | |||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 24 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||
| 222 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||
| 224 | =begin stopwords | ||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||
| 226 | stringwise greps | ||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||
| 228 | =end stopwords | ||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||
| 230 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||
| 232 | Template::Liquid::Condition - Basic Relational, Equality, and Content Operators | ||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||
| 234 | =head1 Description | ||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||
| 236 | These operators evaluate to true/false values. This is used internally but | ||||||||||||||||||||||||||||||||||||||||||||||
| 237 | since you're here... might as well skim it. Nothing new to most people. | ||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||
| 239 | =head1 Relational Operators | ||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||
| 241 | If you're familiar with basic math, you already understand these. | ||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||
| 243 | Any of the following operators can be combined with logical C<and> and C<or>: | ||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 5 > 2 and 'okay' contains 'ok' # true | ||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 4 > 6 or 4 < 6 # true ...silly, but true | ||||||||||||||||||||||||||||||||||||||||||||||
| 247 | # where x = [1 .. 10] | ||||||||||||||||||||||||||||||||||||||||||||||
| 248 | x contains 3 and x contains 0 # false | ||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||
| 250 | Binary C<and> performs a short-circuit logical AND operation. That is, if the | ||||||||||||||||||||||||||||||||||||||||||||||
| 251 | left operand is false, the right operand is not even evaluated. Likewise, | ||||||||||||||||||||||||||||||||||||||||||||||
| 252 | binary C<or> performs a short-circuit logical OR operation. That is, if the | ||||||||||||||||||||||||||||||||||||||||||||||
| 253 | left operand is true, the right operand is not even evaluated. | ||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||
| 255 | =head2 C<< > >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||
| 257 | Binary operator which returns true if the left argument is numerically less | ||||||||||||||||||||||||||||||||||||||||||||||
| 258 | than the right argument. | ||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||
| 260 | Given... | ||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 3 > 4 # false | ||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 4 > 3 # true | ||||||||||||||||||||||||||||||||||||||||||||||
| 264 | # where x == 10 and y == 12 | ||||||||||||||||||||||||||||||||||||||||||||||
| 265 | x > y # false | ||||||||||||||||||||||||||||||||||||||||||||||
| 266 | y > x # true | ||||||||||||||||||||||||||||||||||||||||||||||
| 267 | x > 3 # true | ||||||||||||||||||||||||||||||||||||||||||||||
| 268 | x > x # false | ||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||
| 270 | =head2 C<< < >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||
| 272 | Binary operator which returns true if the left argument is numerically greater | ||||||||||||||||||||||||||||||||||||||||||||||
| 273 | than the right argument. | ||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||
| 275 | Given... | ||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 3 < 4 # true | ||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 4 < 3 # false | ||||||||||||||||||||||||||||||||||||||||||||||
| 279 | # where x == 10 and y == 12 | ||||||||||||||||||||||||||||||||||||||||||||||
| 280 | x < y # true | ||||||||||||||||||||||||||||||||||||||||||||||
| 281 | y < x # false | ||||||||||||||||||||||||||||||||||||||||||||||
| 282 | x < 30 # true | ||||||||||||||||||||||||||||||||||||||||||||||
| 283 | x < x # false | ||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||
| 285 | =head2 C<==> | ||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||
| 287 | Binary operator which returns true if the left argument is numerically equal to | ||||||||||||||||||||||||||||||||||||||||||||||
| 288 | the right argument. | ||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||
| 290 | # where x == 10 and y == 12 | ||||||||||||||||||||||||||||||||||||||||||||||
| 291 | x == y # false | ||||||||||||||||||||||||||||||||||||||||||||||
| 292 | x == 10 # true | ||||||||||||||||||||||||||||||||||||||||||||||
| 293 | y == y # true | ||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||
| 295 | =head2 C<!=> | ||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||
| 297 | Binary operator which returns true if the left argument is numerically not | ||||||||||||||||||||||||||||||||||||||||||||||
| 298 | equal to the right argument. | ||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||
| 300 | # where x == 10 and y == 12 | ||||||||||||||||||||||||||||||||||||||||||||||
| 301 | x != y # true | ||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 5 != 5 # false | ||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||
| 304 | =head2 C<eq> | ||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||
| 306 | Binary operator which returns true if the left argument is stringwise equal to | ||||||||||||||||||||||||||||||||||||||||||||||
| 307 | the right argument. | ||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 'test' eq 'test' # true | ||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 'test' eq 'reset' # false | ||||||||||||||||||||||||||||||||||||||||||||||
| 311 | # where x = 'cool beans' | ||||||||||||||||||||||||||||||||||||||||||||||
| 312 | x eq 'awesome' # false | ||||||||||||||||||||||||||||||||||||||||||||||
| 313 | x eq 'Cool beans' # false | ||||||||||||||||||||||||||||||||||||||||||||||
| 314 | x eq 'cool beans' # true | ||||||||||||||||||||||||||||||||||||||||||||||
| 315 | x eq x # true | ||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||
| 317 | =head2 C<ne> | ||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||
| 319 | Binary operator which returns true if the left argument is stringwise not equal | ||||||||||||||||||||||||||||||||||||||||||||||
| 320 | to the right argument. | ||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 'test' ne 'test' # false | ||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 'test' ne 'reset' # true | ||||||||||||||||||||||||||||||||||||||||||||||
| 324 | # where x = 'cool beans' | ||||||||||||||||||||||||||||||||||||||||||||||
| 325 | x ne 'awesome' # true | ||||||||||||||||||||||||||||||||||||||||||||||
| 326 | x ne 'Cool beans' # true | ||||||||||||||||||||||||||||||||||||||||||||||
| 327 | x ne 'cool beans' # false | ||||||||||||||||||||||||||||||||||||||||||||||
| 328 | x ne x # false | ||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||
| 330 | =head2 C<lt> | ||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||
| 332 | Binary operator which returns true if the left argument is stringwise less than | ||||||||||||||||||||||||||||||||||||||||||||||
| 333 | the right argument. | ||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 'a' lt 'c' # true | ||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 'A' lt 'a' # true | ||||||||||||||||||||||||||||||||||||||||||||||
| 337 | # where x = 'q' | ||||||||||||||||||||||||||||||||||||||||||||||
| 338 | x lt 'r' # true | ||||||||||||||||||||||||||||||||||||||||||||||
| 339 | x lt 'm' # false | ||||||||||||||||||||||||||||||||||||||||||||||
| 340 | x lt x # false | ||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||
| 342 | =head2 C<gt> | ||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||
| 344 | Binary operator which returns true if the left argument is stringwise greater | ||||||||||||||||||||||||||||||||||||||||||||||
| 345 | than the right argument. | ||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 'a' gt 'c' # false | ||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 'A' gt 'a' # false | ||||||||||||||||||||||||||||||||||||||||||||||
| 349 | # where x = 'q' | ||||||||||||||||||||||||||||||||||||||||||||||
| 350 | x gt 'r' # false | ||||||||||||||||||||||||||||||||||||||||||||||
| 351 | x gt 'm' # true | ||||||||||||||||||||||||||||||||||||||||||||||
| 352 | x gt x # true | ||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||
| 354 | =head1 Other Operators | ||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||
| 356 | These are nice things to have around... | ||||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||
| 358 | =head2 C<contains> | ||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||
| 360 | The C<contains> operator is context sensitive. | ||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||
| 362 | =head3 Strings | ||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||
| 364 | If the variable on the left is a string, this operator searches the string for | ||||||||||||||||||||||||||||||||||||||||||||||
| 365 | a pattern match, and (as if in scalar context) returns true if it succeeds, | ||||||||||||||||||||||||||||||||||||||||||||||
| 366 | false if it fails. | ||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||
| 368 | Note that this is a simple C<$x =~ qr[${y}]> match. Case matters. | ||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||
| 370 | Given... | ||||||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||||||
| 372 | # where x = 'The Angels have the police box!' | ||||||||||||||||||||||||||||||||||||||||||||||
| 373 | x contains 'police' # true | ||||||||||||||||||||||||||||||||||||||||||||||
| 374 | x contains 'Police' # false | ||||||||||||||||||||||||||||||||||||||||||||||
| 375 | x contains 'police box?' # false | ||||||||||||||||||||||||||||||||||||||||||||||
| 376 | x contains 'police box!' # true | ||||||||||||||||||||||||||||||||||||||||||||||
| 377 | x contains x # true | ||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||
| 379 | =head3 Lists | ||||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||||
| 381 | If the variable is a list, the operator greps the list to find the attribute. | ||||||||||||||||||||||||||||||||||||||||||||||
| 382 | If found, a true value is returned. Otherwise, the return value is false. | ||||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||||
| 384 | Given... | ||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||
| 386 | # where x = ['one', 'two', 'three'] | ||||||||||||||||||||||||||||||||||||||||||||||
| 387 | x contains 'five' # false | ||||||||||||||||||||||||||||||||||||||||||||||
| 388 | x contains 'six' # false | ||||||||||||||||||||||||||||||||||||||||||||||
| 389 | x contains 'one' # true | ||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||
| 391 | =head3 Hashes | ||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||
| 393 | If the variable is a hash reference, the operator returns true if the specified | ||||||||||||||||||||||||||||||||||||||||||||||
| 394 | element in the hash has ever been initialized, even if the corresponding value | ||||||||||||||||||||||||||||||||||||||||||||||
| 395 | is undefined. | ||||||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||||||
| 397 | Given... | ||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||
| 399 | # where x = { okay => 'okay', blah => undef } | ||||||||||||||||||||||||||||||||||||||||||||||
| 400 | x contains 'okay' # false | ||||||||||||||||||||||||||||||||||||||||||||||
| 401 | x contains 'alright' # false | ||||||||||||||||||||||||||||||||||||||||||||||
| 402 | x contains 'blah' # true | ||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||
| 404 | =head1 Known Bugs | ||||||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||||||
| 406 | None right now. Give it time. | ||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||
| 408 | =head1 Author | ||||||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||||||
| 410 | Sanko Robinson <sanko@cpan.org> - http://sankorobinson.com/ | ||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||
| 412 | =head1 License and Legal | ||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||
| 414 | Copyright (C) 2009-2022 by Sanko Robinson E<lt>sanko@cpan.orgE<gt> | ||||||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||||||
| 416 | This program is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||||||
| 417 | the terms of The Artistic License 2.0. See the F<LICENSE> file included with | ||||||||||||||||||||||||||||||||||||||||||||||
| 418 | this distribution or http://www.perlfoundation.org/artistic_license_2_0. For | ||||||||||||||||||||||||||||||||||||||||||||||
| 419 | clarification, see http://www.perlfoundation.org/artistic_2_0_notes. | ||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||
| 421 | When separated from the distribution, all original POD documentation is covered | ||||||||||||||||||||||||||||||||||||||||||||||
| 422 | by the Creative Commons Attribution-Share Alike 3.0 License. See | ||||||||||||||||||||||||||||||||||||||||||||||
| 423 | http://creativecommons.org/licenses/by-sa/3.0/us/legalcode. For clarification, | ||||||||||||||||||||||||||||||||||||||||||||||
| 424 | see http://creativecommons.org/licenses/by-sa/3.0/us/. | ||||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||
| 426 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||