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