blib/lib/UR/BoolExpr/Template/PropertyComparison/NotIn.pm untested

filter: Statementstmt 0.0% 0 / 41 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 6 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 62 SCAR 34.0
CC
5
Cov
0%
_compare
30.0
BEGIN
2.0
BEGIN
2.0
CRAP 30.0
1  
2 package UR::BoolExpr::Template::PropertyComparison::NotIn;
3  
4 use strict;
5 use warnings;
6 use UR;
7 our $VERSION = "0.46"; # UR $VERSION;
8  
9 UR::Object::Type->define(
10 class_name => __PACKAGE__,
11 is => ['UR::BoolExpr::Template::PropertyComparison'],
12 doc => "Returns false if any of the property's values appears in the comparison value list",
13 );
14  
15 sub _compare {
16 my ($class,$comparison_values,@property_values) = @_;
17  
18 if (@property_values == 1 and ref($property_values[0]) eq 'ARRAY') {
19 @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 if (! @property_values and !defined($comparison_values->[-1])) {
25 return '';
26 }
27  
28 my($pv_idx, $cv_idx);
29 no warnings;
30 my $sorter = sub { return $property_values[$pv_idx] cmp $comparison_values->[$cv_idx] };
31 use warnings;
32  
33 # Binary search within @$comparison_values
34 my $cv_min = 0;
35 my $cv_max = $#$comparison_values;
36 for ( $pv_idx = 0; $pv_idx < @property_values; $pv_idx++ ) {
37 do {
38 $cv_idx = ($cv_min + $cv_max) >> 1;
39 my $result = &$sorter;
40 if (!$result) {
41 return '';
42 } elsif ($result > 0) {
43 $cv_min = $cv_idx + 1;
44 } else {
45 $cv_max = $cv_idx - 1;
46 }
47 } until ($cv_min > $cv_max);
48 }
49 return 1;
50 }
51  
52  
53 1;
54  
55 =pod
56  
57 =head1 NAME
58  
59 UR::BoolExpr::Template::PropertyComparison::NotIn - perform a negated In comparison
60  
61 =head1 DESCRIPTION
62  
63 Returns false if any of the property's values appears in the comparison value list
64  
65 =cut