lib/UR/BoolExpr/Template/PropertyComparison/In.pm

filter: Statementstmt 47.3% 18 / 38 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 71.4% 5 / 7 Podpod n/a totaltotal 34.3% 23 / 67 CC 9 SCAR 36.2
CC
9
Cov
32%
_compare
61.2
__ANON__
2.0
BEGIN
1.0
CRAP 37.2
« blib/lib/UR/Namespace/Command/Test/TrackObjectRelease.pm ↑ Summary blib/lib/UR/DataSource/Default.pm »
1  
2 package UR::BoolExpr::Template::PropertyComparison::In;
3  
4 266 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 266 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 266 ▶use UR;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 266 our $VERSION = "0.47"; # UR $VERSION;
8  
9 266 UR::Object::Type->define(
10 class_name => __PACKAGE__,
11 is => ['UR::BoolExpr::Template::PropertyComparison'],
12 doc => "Returns true if any of the property's values appears in the comparison value list",
13 );
14  
15 0 ▶sub _compare {
Subroutine _compare: not called CC=9 SCAR=41.1
16 0 my ($class,$comparison_values,@property_values) = @_;
17  
18 0 ▶ if (@property_values == 1 and ref($property_values[0]) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (@property_values == 1 and ref $property_values[0] eq "ARRAY") 0 0 0
Condition0%0/3
@property_values == 1 and ref $property_values[0] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
@property_values == 1 and ref $property_values[0] eq "ARRAY"
@property_values == 1 ref $property_values[0] eq "ARRAY"
Truth table0%0/3
A and B
A= @property_values == 1B= ref $property_values[0] eq "ARRAY"
ABresult
0X0
100
111
19 0 @property_values = @{$property_values[0]};
20 }
21  
22 # undef should match missing values, which will be sorted at the end - the sorter in
23 # UR::BoolExpr::resolve() takes care of the sorting for us
24 0 ▶ if (! @property_values and !defined($comparison_values->[-1])) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@property_values or defined $comparison_values->[-1]) 0 0 0
Condition0%0/3
@property_values or defined $comparison_values->[-1]
l!l&&r!l&&!r
000
MC/DC0%0/2
@property_values or defined $comparison_values->[-1]
@property_values defined $comparison_values->[-1]
Truth table0%0/3
A or B
A= @property_valuesB= defined $comparison_values->[-1]
ABresult
1X1
011
000
25 0 return 1;
26 }
27  
28 0 my($pv_idx, $cv_idx);
29 266 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 0 ▶ my $sorter = sub { return $property_values[$pv_idx] cmp $comparison_values->[$cv_idx] };
Subroutine __ANON__: not called CC=1 SCAR=6.9
31 266 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 # Binary search within @$comparison_values
34 0 ▶ for ( $pv_idx = 0; $pv_idx < @property_values; $pv_idx++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pv_idx < @property_values) 0 0 0
35 0 my $cv_min = 0;
36 0 my $cv_max = $#$comparison_values;
37 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$cv_min > $cv_max or do { do { $cv_idx = $cv_min + $cv_max >> 1; my $result = &$sorter; if (not $result) { return 1; } elsif ($result > 0) { $cv_min = $cv_idx + 1; } else { $cv_max = $cv_idx - 1; } } } 0 0 0
38 0 $cv_idx = ($cv_min + $cv_max) >> 1;
39 0 my $result = &$sorter;
40 0 ▶ if (!$result) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $result) { } 0 0 0
elsif ($result > 0) { } 0 0 0
41 0 return 1;
42 } elsif ($result > 0) {
43 0 $cv_min = $cv_idx + 1;
44 } else {
45 0 $cv_max = $cv_idx - 1;
46 }
47 } until ($cv_min > $cv_max);
48 }
49 0 return '';
50 }
51  
52 266 1;
53  
54 =pod
55  
56 =head1 NAME
57  
58 UR::BoolExpr::Template::PropertyComparison::In - perform an In test
59  
60 =head1 DESCRIPTION
61  
62 Returns true if any of the property's values appears in the comparison value list.
63 Think of 'in' as short for 'intersect', and not just SQL's 'IN' operator.
64  
65 =cut
« blib/lib/UR/Namespace/Command/Test/TrackObjectRelease.pm ↑ Summary blib/lib/UR/DataSource/Default.pm »