LINQ/FieldSet/Assertion.pm

filter: Statementstmt 95.8% 231 / 241 Branchbran 78.7% 63 / 80 Conditioncond 78.9% 15 / 19 MC/DCmcdc 63.6% 7 / 11 Subroutinesub 96.3% 53 / 55 Podpod 100% 6 / 6 totaltotal 91.0% 375 / 412 SCAR 40.1
CC
53
Cov
91%
__ANON__
19.4
_make_is_check
14.4
_make_to_check
7.0
CRAP 55.1
« LINQ/Collection.pm ↑ Summary LINQ/Iterator.pm »
1 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package LINQ::FieldSet::Assertion;
6  
7 my $_process_args = sub {
8 9 ▶ require Scalar::Util;
Subroutine __ANON__: called CC=5 SCAR=16.4
9 9 ▶ if ( Scalar::Util::blessed( $_[0] )
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($_[0]) and builtin::blessed($_[1]) and @_ < 4) 3 6 9
Condition66%4/6
builtin::blessed($_[0]) and builtin::blessed($_[1]) and @_ < 4
!ll&&!rl&&r
603
builtin::blessed($_[0]) and builtin::blessed($_[1])
!ll&&!rl&&r
063
MC/DC33%1/3
builtin::blessed($_[0]) and builtin::blessed($_[1]) and @_ < 4
builtin::blessed($_[0]) builtin::blessed($_[1]) @_ < 4
Truth table50%2/4
A and B and C
A= builtin::blessed($_[0])B= builtin::blessed($_[1])C= @_ < 4
ABCresult
0XX0
10X0
1100
1111
10 and Scalar::Util::blessed( $_[1] )
11 and @_ < 4 )
12 {
13 3 ▶ return $_[2] ? ( $_[1], $_[0] ) : ( $_[0], $_[1] );
Branch: 1 branch
BranchTrueFalseTotal
$_[2] ? : 0 3 3
14 }
15
16 6 my ( $self, @other ) = @_;
17 6 my $other = __PACKAGE__->new( @other );
18 6 return ( $self, $other );
19 2 };
20  
21 2 our $AUTHORITY = 'cpan:TOBYINK';
22 2 our $VERSION = '0.002';
23  
24 2 ▶use Class::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 2 ▶use parent qw( LINQ::FieldSet );
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 2 ▶use LINQ::Util::Internal ();
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 use overload (
30 'fallback' => !!1,
31 0 ▶ q[bool] => sub { !! 1 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
32 2 q[""] => 'to_string',
33 q[&{}] => 'coderef',
34 q[|] => 'or',
35 q[&] => 'and',
36 q[~] => 'not',
37 2 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 sub _known_parameter_names {
40 41 ▶ my ( $self ) = ( shift );
Subroutine _known_parameter_names: called CC=1 SCAR=0.0
41
42 return (
43 41 $self->SUPER::_known_parameter_names,
44 'is' => 1,
45 'in' => 1,
46 'like' => 1,
47 'match' => 1,
48 'to' => 1,
49 'cmp' => 1,
50 'numeric' => 0,
51 'string' => 0,
52 'nix' => 0,
53 'nocase' => 0,
54 );
55 } #/ sub _known_parameter_names
56  
57 sub coderef {
58 69 ▶ my ( $self ) = ( shift );
Subroutine coderef: called CC=2 SCAR=6.9
Pod documented
59 69 ▶ $self->{coderef} ||= $self->_build_coderef;
Condition100%3/3
$self->{"coderef"} ||= $self->_build_coderef
l!l&&r!l&&!r
29373
MC/DC100%2/2
$self->{"coderef"} ||= $self->_build_coderef
$self->{"coderef"} $self->_build_coderef
Truth table100%3/3
A ||= B
A= $self->{"coderef"}B= $self->_build_coderef
ABresult
1X1
011
000
60 }
61  
62 sub BUILD {
63 41 ▶ my ( $self ) = ( shift );
Subroutine BUILD: called CC=2 SCAR=6.9
Pod documented
64 41 ▶ if ( $self->seen_asterisk ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->seen_asterisk) 1 40 41
65 1 LINQ::Util::Internal::throw(
66 "CallerError",
67 message => "Field '*' does not make sense for assertions",
68 );
69 }
70 }
71  
72 sub _build_coderef {
73 40 ▶ my ( $self ) = ( shift );
Subroutine _build_coderef: called CC=1 SCAR=0.0
74 40 my @checks = map $self->_make_check( $_ ), @{ $self->fields };
75 return sub {
76 73 ▶ for my $check ( @checks ) {
Subroutine __ANON__: called CC=3 SCAR=11.0
77 75 ▶ return !!0 unless $check->( $_ );
Branch: 1 branch
BranchTrueFalseTotal
unless &$check($_) 39 36 75
78 }
79 34 return !!1;
80 37 };
81 } #/ sub _build_coderef
82  
83 {
84 2 my %makers = (
85 'is' => '_make_is_check',
86 'in' => '_make_in_check',
87 'to' => '_make_to_check',
88 'like' => '_make_like_check',
89 'match' => '_make_match_check',
90 );
91  
92 sub _make_check {
93 41 ▶ my ( $self, $field ) = ( shift, @_ );
Subroutine _make_check: called CC=5 SCAR=16.1
94
95 41 my @found;
96 41 for my $key ( sort keys %makers ) {
97 205 ▶ push @found, $key if exists $field->params->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $field->params->{$key} 41 164 205
98 }
99
100 41 ▶ if ( @found > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@found > 1) 1 40 41
101 1 my $params = join q[, ], map "-$_", @found;
102 1 LINQ::Util::Internal::throw(
103 "CallerError",
104 1 message => "Multiple conflicting assertions ($params) found for field '@{[ $field->name ]}'",
105 );
106 }
107
108 40 ▶ if ( @found == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@found == 0) 1 39 40
109 1 LINQ::Util::Internal::throw(
110 "CallerError",
111 1 message => "No assertions found for field '@{[ $field->name ]}'",
112 );
113 }
114
115 39 my $method = $makers{ $found[0] };
116 39 return $self->$method( $field );
117 }
118 }
119  
120 {
121 2 my %templates = (
122 'numeric ==' => '%s == %s',
123 'numeric !=' => '%s != %s',
124 'numeric >' => '%s > %s',
125 'numeric >=' => '%s >= %s',
126 'numeric <' => '%s < %s',
127 'numeric <=' => '%s <= %s',
128 'string ==' => '%s eq %s',
129 'string !=' => '%s ne %s',
130 'string >' => '%s gt %s',
131 'string >=' => '%s ge %s',
132 'string <' => '%s lt %s',
133 'string <=' => '%s le %s',
134 'null ==' => '! defined( %s )',
135 );
136
137 sub _make_is_check {
138 22 ▶ my ( $self, $field ) = ( shift, @_ );
Subroutine _make_is_check: called CC=14 SCAR=26.7
139 22 my $getter = $field->getter;
140
141 22 my $expected = $field->params->{is};
142 22 ▶ my $cmp = $field->params->{cmp} || "==";
Condition100%2/2
$field->params->{'cmp'} || '=='
l!l
517
MC/DC100%1/1
$field->params->{'cmp'} || '=='
$field->params->{'cmp'}
Truth table100%2/2
A
A= $field->params->{'cmp'}
Aresult
11
00
143 my $type =
144 $field->params->{numeric} ? 'numeric'
145 22 ▶ : $field->params->{string} ? 'string'
Branch: 5 branches
BranchTrueFalseTotal
$field->params->{'numeric'} ? : 0 22 22
$field->params->{'string'} ? : 0 22 22
!defined($expected) ? : 2 20 22
$expected =~ /^[0-9]+(?:\.[0-9]+)$/ ? : 1 19 20
!ref($expected) ? : 19 0 19
146 : !defined( $expected ) ? 'null'
147 : $expected =~ /^[0-9]+(?:\.[0-9]+)$/ ? 'numeric'
148 : !ref( $expected ) ? 'string'
149 : 'numeric';
150 22 ▶ my $template = $templates{"$type $cmp"}
Branch: 1 branch
BranchTrueFalseTotal
my $template = $templates{"$type $cmp"} or LINQ::Util::Internal::throw("CallerError", "message", "Unexpected comparator '${cmp}' for type '${type}'") 1 21 22
151 or LINQ::Util::Internal::throw(
152 "CallerError",
153 message => "Unexpected comparator '$cmp' for type '$type'",
154 );
155
156 21 my $guts;
157 21 ▶ if ( $type eq 'null' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'null') { } 2 19 21
elsif ($field->params->{'nocase'}) { } 1 18 19
158 2 $guts = sprintf( $template, '$getter->( $_ )' );
159 }
160 elsif ( $field->params->{nocase} ) {
161 1 ▶ my $fold = ( $] > 5.016 ) ? 'CORE::fc' : 'lc';
Branch: 1 branch
BranchTrueFalseTotal
$] > 5.016 ? : 1 0 1
162 $guts = sprintf(
163 $template,
164 "$fold( \$getter->( \$_ ) )",
165 1 ▶ ref( $expected ) ? "$fold( \$expected )" : do {
Branch: 1 branch
BranchTrueFalseTotal
ref $expected ? : 0 1 1
166 1 require B;
167 1 "$fold( " . B::perlstring( $expected ) . ' )';
168 },
169 );
170 } #/ elsif ( $field->params->{...})
171 else {
172 $guts = sprintf(
173 $template,
174 '$getter->( $_ )',
175 18 ▶ ref( $expected ) ? '$expected' : do {
Branch: 1 branch
BranchTrueFalseTotal
ref $expected ? : 0 18 18
176 18 require B;
177 18 B::perlstring( $expected );
178 },
179 );
180 } #/ else [ if ( $type eq 'null' )]
181
182 21 ▶ if ( $field->params->{nix} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field->params->{"nix"}) 1 20 21
183 1 $guts = "!( $guts )";
184 }
185
186 2 ▶ no warnings qw( uninitialized );
Subroutine BEGIN: called CC=1 SCAR=0.0
187 21 return eval "sub { $guts }";
188 }
189
190 sub _make_to_check {
191 7 ▶ my ( $self, $field ) = ( shift, @_ );
Subroutine _make_to_check: called CC=7 SCAR=19.5
192 7 my $getter = $field->getter;
193
194 7 my $other = 'LINQ::Field'->new( value => $field->params->{to} )->getter;
195 7 ▶ my $cmp = $field->params->{cmp} || "==";
Condition100%2/2
$field->params->{'cmp'} || '=='
l!l
25
MC/DC100%1/1
$field->params->{'cmp'} || '=='
$field->params->{'cmp'}
Truth table100%2/2
A
A= $field->params->{'cmp'}
Aresult
11
00
196 7 ▶ my $type = $field->params->{string} ? 'string' : 'numeric';
Branch: 1 branch
BranchTrueFalseTotal
$field->params->{'string'} ? : 3 4 7
197 7 ▶ my $template = $templates{"$type $cmp"}
Branch: 1 branch
BranchTrueFalseTotal
my $template = $templates{"$type $cmp"} or LINQ::Util::Internal::throw("CallerError", "message", "Unexpected comparator '${cmp}' for type '${type}'") 0 7 7
198 or LINQ::Util::Internal::throw(
199 "CallerError",
200 message => "Unexpected comparator '$cmp' for type '$type'",
201 );
202
203 7 my $guts;
204 7 ▶ if ( $field->params->{nocase} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field->params->{'nocase'}) { } 2 5 7
205 2 ▶ my $fold = ( $] > 5.016 ) ? 'CORE::fc' : 'lc';
Branch: 1 branch
BranchTrueFalseTotal
$] > 5.016 ? : 2 0 2
206 2 $guts = sprintf(
207 $template,
208 "$fold( \$getter->( \$_ ) )",
209 "$fold( \$other->( \$_ ) )",
210 );
211 } #/ elsif ( $field->params->{...})
212 else {
213 5 $guts = sprintf(
214 $template,
215 '$getter->( $_ )',
216 '$other->( $_ )',
217 );
218 } #/ else [ if ( $type eq 'null' )]
219
220 7 ▶ if ( $field->params->{nix} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field->params->{"nix"}) 1 6 7
221 1 $guts = "!( $guts )";
222 }
223
224 2 ▶ no warnings qw( uninitialized );
Subroutine BEGIN: called CC=1 SCAR=0.0
225 7 return eval "sub { $guts }";
226 }
227 }
228  
229 2 sub _make_in_check {
230 3 ▶ my ( $self, $field ) = ( shift, @_ );
Subroutine _make_in_check: called CC=2 SCAR=6.9
231 3 my $getter = $field->getter;
232 3 my @expected = @{ $field->params->{in} };
233
234 3 my $nix = ! $field->params->{nix};
235
236 3 ▶ if ( $field->params->{nocase} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field->params->{'nocase'}) { } 1 2 3
237 return sub {
238 2 ▶ my $value = lc $getter->( $_ );
Subroutine __ANON__: called CC=3 SCAR=11.0
239 2 for my $expected ( @expected ) {
240 3 ▶ return !!$nix if $value eq lc $expected;
Branch: 1 branch
BranchTrueFalseTotal
if $value eq lc $expected 1 2 3
241 }
242 1 return !$nix;
243 1 };
244 }
245 else {
246 return sub {
247 4 ▶ my $value = $getter->( $_ );
Subroutine __ANON__: called CC=3 SCAR=11.0
248 4 for my $expected ( @expected ) {
249 7 ▶ return !!$nix if $value eq $expected;
Branch: 1 branch
BranchTrueFalseTotal
if $value eq $expected 1 6 7
250 }
251 3 return !$nix;
252 2 };
253 }
254 }
255  
256 {
257 my $_like_to_regexp = sub {
258 5 ▶ my ( $like, $ci ) = @_;
Subroutine __ANON__: called CC=12 SCAR=29.7
259 5 my $re = '';
260 5 my %anchors = (
261 start => substr( $like, 0, 1 ) ne '%',
262 end => substr( $like, -1, 1 ) ne '%',
263 );
264 5 my @parts = split qr{(\\*[.%])}, $like;
265 5 for my $p ( @parts ) {
266 10 ▶ next unless length $p;
Branch: 1 branch
BranchTrueFalseTotal
unless length $p 0 10 10
267 10 my $backslash_count =()= $p =~ m{(\\)}g;
268 10 my $wild_count =()= $p =~ m{([%.])}g;
269 10 ▶ if ( $wild_count ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wild_count) { } 5 5 10
270 5 ▶ if ( $backslash_count && $backslash_count % 2 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($backslash_count and $backslash_count % 2) { } 0 5 5
elsif ($backslash_count) { } 0 5 5
Condition33%1/3
$backslash_count and $backslash_count % 2
!ll&&!rl&&r
500
MC/DC0%0/2
$backslash_count and $backslash_count % 2
$backslash_count $backslash_count % 2
Truth table33%1/3
A and B
A= $backslash_countB= $backslash_count % 2
ABresult
0X0
100
111
271 0 my $last = substr( $p, -2, 2, '' );
272 0 $p =~ s{\\\\}{\\};
273 0 $re .= quotemeta( $p . substr( $last, -1, 1 ) );
274 }
275 elsif ( $backslash_count ) {
276 0 my $last = substr( $p, -1, 1, '' );
277 0 $p =~ s{\\\\}{\\};
278 0 ▶ $re .= quotemeta( $p ) . ( $last eq '%' ? '.*' : '.' );
Branch: 1 branch
BranchTrueFalseTotal
$last eq '%' ? : 0 0 0
279 }
280 else {
281 5 ▶ $re .= $p eq '%' ? '.*' : '.';
Branch: 1 branch
BranchTrueFalseTotal
$p eq '%' ? : 5 0 5
282 }
283 } #/ if ( $wild_count )
284 else {
285 5 $p =~ s{\\(.)}{$1}g;
286 5 $re .= quotemeta( $p );
287 }
288 } #/ for my $p ( @parts )
289
290 5 ▶ substr( $re, 0, 0, '\A' ) if $anchors{start};
Branch: 1 branch
BranchTrueFalseTotal
if $anchors{"start"} 5 0 5
291 5 ▶ $re .= '\z' if $anchors{end};
Branch: 1 branch
BranchTrueFalseTotal
if $anchors{"end"} 0 5 5
292
293 5 ▶ $ci ? qr/$re/i : qr/$re/;
Branch: 1 branch
BranchTrueFalseTotal
$ci ? : 3 2 5
294 2 };
295  
296 sub _make_like_check {
297 5 ▶ my ( $self, $field ) = ( shift, @_ );
Subroutine _make_like_check: called CC=2 SCAR=6.9
298 5 my $getter = $field->getter;
299
300 my $match = $_like_to_regexp->(
301 $field->params->{like},
302 $field->params->{nocase},
303 5 );
304
305 5 ▶ if ( $field->params->{nix} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field->params->{'nix'}) { } 1 4 5
306 return sub {
307 2 ▶ my $value = $getter->( $_ );
Subroutine __ANON__: called CC=1 SCAR=0.0
308 2 $value !~ $match;
309 1 };
310 }
311 else {
312 return sub {
313 6 ▶ my $value = $getter->( $_ );
Subroutine __ANON__: called CC=1 SCAR=0.0
314 6 $value =~ $match;
315 4 };
316 }
317 }
318 }
319  
320 2 sub _make_match_check {
321 2 ▶ my ( $self, $field ) = ( shift, @_ );
Subroutine _make_match_check: called CC=2 SCAR=6.9
322 2 my $getter = $field->getter;
323
324 2 my $match = $field->params->{match};
325
326 2 require match::simple;
327
328 2 ▶ if ( $field->params->{nix} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field->params->{'nix'}) { } 1 1 2
329 return sub {
330 2 ▶ my $value = $getter->( $_ );
Subroutine __ANON__: called CC=1 SCAR=0.0
331 2 not match::simple::match( $value, $match );
332 1 };
333 }
334 else {
335 return sub {
336 2 ▶ my $value = $getter->( $_ );
Subroutine __ANON__: called CC=1 SCAR=0.0
337 2 match::simple::match( $value, $match );
338 1 };
339 }
340 }
341  
342 sub not {
343 4 ▶ my ( $self ) = ( shift );
Subroutine not: called CC=1 SCAR=0.0
Pod documented
344 4 return 'LINQ::FieldSet::Assertion::NOT'->new(
345 left => $self,
346 );
347 }
348  
349 sub and {
350 5 ▶ my ( $self, $other ) = &$_process_args;
Subroutine and: called CC=1 SCAR=0.0
Pod documented
351 5 return 'LINQ::FieldSet::Assertion::AND'->new(
352 left => $self,
353 right => $other,
354 );
355 }
356  
357 sub or {
358 1 ▶ my ( $self, $other ) = &$_process_args;
Subroutine or: called CC=1 SCAR=0.0
Pod documented
359 1 return 'LINQ::FieldSet::Assertion::OR'->new(
360 left => $self,
361 right => $other,
362 );
363 }
364  
365 sub to_string {
366 0 ▶ my ( $self ) = ( shift );
Subroutine to_string: not called CC=1 SCAR=6.9
Pod documented
367 0 sprintf 'check_fields(%s)', join q[, ], map $_->name, @{ $self->fields };
368 }
369  
370 package LINQ::FieldSet::Assertion::Combination;
371  
372 2 our $AUTHORITY = 'cpan:TOBYINK';
373 2 our $VERSION = '0.002';
374  
375 2 ▶use Role::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
376 2 requires( qw/ left right _build_coderef / );
377  
378 sub coderef {
379 20 ▶ my ( $self ) = ( shift );
Subroutine coderef: called CC=2 SCAR=6.9
380 20 ▶ $self->{coderef} ||= $self->_build_coderef;
Condition100%3/3
$self->{"coderef"} ||= $self->_build_coderef
l!l&&r!l&&!r
7121
MC/DC100%2/2
$self->{"coderef"} ||= $self->_build_coderef
$self->{"coderef"} $self->_build_coderef
Truth table100%3/3
A ||= B
A= $self->{"coderef"}B= $self->_build_coderef
ABresult
1X1
011
000
381 }
382  
383 sub not {
384 1 ▶ my ( $self ) = ( shift );
Subroutine not: called CC=1 SCAR=0.0
385 1 return 'LINQ::FieldSet::Assertion::NOT'->new(
386 left => $self,
387 );
388 }
389  
390 sub and {
391 1 ▶ my ( $self, $other ) = &$_process_args;
Subroutine and: called CC=1 SCAR=0.0
392 1 return 'LINQ::FieldSet::Assertion::AND'->new(
393 left => $self,
394 right => $other,
395 );
396 }
397  
398 sub or {
399 2 ▶ my ( $self, $other ) = &$_process_args;
Subroutine or: called CC=1 SCAR=0.0
400 2 return 'LINQ::FieldSet::Assertion::OR'->new(
401 left => $self,
402 right => $other,
403 );
404 }
405  
406 package LINQ::FieldSet::Assertion::NOT;
407  
408 2 our $AUTHORITY = 'cpan:TOBYINK';
409 2 our $VERSION = '0.002';
410  
411 2 ▶use Class::Tiny qw( left );
Subroutine BEGIN: called CC=1 SCAR=0.0
412 2 ▶use Role::Tiny::With ();
Subroutine BEGIN: called CC=1 SCAR=0.0
413 2 Role::Tiny::With::with( 'LINQ::FieldSet::Assertion::Combination' );
414  
415 2 ▶use overload ();
Subroutine BEGIN: called CC=1 SCAR=0.0
416 2 'overload'->import(
417 q[&{}] => 'coderef',
418 q[|] => 'or',
419 q[&] => 'and',
420 q[~] => 'not',
421 );
422  
423 sub _build_coderef {
424 3 ▶ my ( $self ) = ( shift );
Subroutine _build_coderef: called CC=1 SCAR=0.0
425 3 my $left = $self->left->coderef;
426 3 ▶ return sub { not $left->( $_ ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
427 }
428  
429 sub not {
430 1 ▶ my ( $self ) = ( shift );
Subroutine not: called CC=1 SCAR=0.0
431 1 return $self->left;
432 }
433  
434 sub right {
435 1 ▶ LINQ::Util::Internal::throw(
Subroutine right: called CC=1 SCAR=0.0
436 "InternalError",
437 message => 'Unexpected second branch to NOT.',
438 );
439 }
440  
441 package LINQ::FieldSet::Assertion::AND;
442  
443 2 our $AUTHORITY = 'cpan:TOBYINK';
444 2 our $VERSION = '0.002';
445  
446 2 ▶use Class::Tiny qw( left right );
Subroutine BEGIN: called CC=1 SCAR=0.0
447 2 ▶use Role::Tiny::With ();
Subroutine BEGIN: called CC=1 SCAR=0.0
448 2 Role::Tiny::With::with( 'LINQ::FieldSet::Assertion::Combination' );
449  
450 2 ▶use overload ();
Subroutine BEGIN: called CC=1 SCAR=0.0
451 2 'overload'->import(
452 q[&{}] => 'coderef',
453 q[|] => 'or',
454 q[&] => 'and',
455 q[~] => 'not',
456 );
457  
458 sub _build_coderef {
459 6 ▶ my ( $self ) = ( shift );
Subroutine _build_coderef: called CC=1 SCAR=0.0
460 6 my $left = $self->left->coderef;
461 6 my $right = $self->right->coderef;
462 6 ▶ return sub { $left->( $_ ) and $right->( $_ ) };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
&$left($_) and &$right($_) 7 10 17
463 }
464  
465 package LINQ::FieldSet::Assertion::OR;
466  
467 2 our $AUTHORITY = 'cpan:TOBYINK';
468 2 our $VERSION = '0.002';
469  
470 2 ▶use Class::Tiny qw( left right );
Subroutine BEGIN: called CC=1 SCAR=0.0
471 2 ▶use Role::Tiny::With ();
Subroutine BEGIN: called CC=1 SCAR=0.0
472 2 Role::Tiny::With::with( 'LINQ::FieldSet::Assertion::Combination' );
473  
474 2 ▶use overload ();
Subroutine BEGIN: called CC=1 SCAR=0.0
475 2 'overload'->import(
476 q[&{}] => 'coderef',
477 q[|] => 'or',
478 q[&] => 'and',
479 q[~] => 'not',
480 );
481  
482 sub _build_coderef {
483 3 ▶ my ( $self ) = ( shift );
Subroutine _build_coderef: called CC=1 SCAR=0.0
484 3 my $left = $self->left->coderef;
485 3 my $right = $self->right->coderef;
486 3 ▶ return sub { $left->( $_ ) or $right->( $_ ) };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
&$left($_) or &$right($_) 6 4 10
487 }
488  
489 2 1;
490  
491 __END__
492  
493 =pod
494  
495 =encoding utf-8
496  
497 =head1 NAME
498  
499 LINQ::FieldSet::Assertion - represents an SQL-WHERE-like assertion/check
500  
501 =head1 DESCRIPTION
502  
503 LINQ::FieldSet::Assertion is a subclass of L<LINQ::FieldSet>.
504  
505 This is used internally by LINQ and you probably don't need to know about it
506 unless you're writing very specific extensions for LINQ. The end user
507 interface is the C<check_fields> function in L<LINQ::Util>.
508  
509 =head1 CONSTRUCTOR
510  
511 =over
512  
513 =item C<< new( ARGSLIST ) >>
514  
515 Constructs a fieldset from a list of fields like:
516  
517 'LINQ::FieldSet::Assertion'->new(
518 'field1', -param1 => 'value1', -param2,
519 'field2', -param1 => 'value2',
520 );
521  
522 Allowed parameters are:
523 C<< -is >> (followed by a value),
524 C<< -to >> (followed by a value),
525 C<< -in >> (followed by a value),
526 C<< -like >> (followed by a value),
527 C<< -match >> (followed by a value),
528 C<< -cmp >> (followed by a value),
529 C<< -numeric >> (no value),
530 C<< -string >> (no value),
531 C<< -not >> (no value), and
532 C<< -nocase >> (no value).
533  
534 =back
535  
536 =begin trustme
537  
538 =item BUILD
539  
540 =end trustme
541  
542 =head1 METHODS
543  
544 =over
545  
546 =item C<< and( OTHER ) >>
547  
548 Return a LINQ::FieldSet::Assertion::AND object which is a conjunction of this
549 assertion and another assertion.
550  
551 =item C<< or( OTHER ) >>
552  
553 Return a LINQ::FieldSet::Assertion::OR object which is an inclusive disjunction
554 of this assertion and another assertion.
555  
556 =item C<not>
557  
558 Return a LINQ::FieldSet::Assertion::NOT object which is the negation of this
559 assertion.
560  
561 =item C<coderef>
562  
563 Gets a coderef for this assertion; the coderef operates on C<< $_ >>.
564  
565 =item C<to_string>
566  
567 Basic string representation of the fieldset.
568  
569 =back
570  
571 The LINQ::FieldSet::Assertion::{AND,OR,NOT} classes are lightweight classes
572 which also implement the C<and>, C<or>, C<not>, and C<coderef> methods, and
573 have the same overloading as LINQ::FieldSet::Assertion, but do not inherit
574 from it.
575  
576 =head1 OVERLOADING
577  
578 This class overloads
579 C<< "" >> to call the C<< to_string >> method;
580 C<< & >> to call the C<< and >> method;
581 C<< | >> to call the C<< or >> method;
582 C<< ~ >> to call the C<< not >> method; and
583 C<< &{} >> to call the C<< coderef >> method.
584  
585 =head1 BUGS
586  
587 Please report any bugs to
588 L<http://rt.cpan.org/Dist/Display.html?Queue=LINQ>.
589  
590 =head1 SEE ALSO
591  
592 L<LINQ::FieldSet>, L<LINQ::Util>.
593  
594 =head1 AUTHOR
595  
596 Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
597  
598 =head1 COPYRIGHT AND LICENCE
599  
600 This software is copyright (c) 2021 by Toby Inkster.
601  
602 This is free software; you can redistribute it and/or modify it under
603 the same terms as the Perl 5 programming language system itself.
604  
605 =head1 DISCLAIMER OF WARRANTIES
606  
607 THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
608 WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
609 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
« LINQ/Collection.pm ↑ Summary LINQ/Iterator.pm »