| 1 | package UR::BoolExpr::Template::Or; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 266 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 266 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 266 | our $VERSION = "0.47"; # UR $VERSION; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 266 | require UR; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 266 | UR::Object::Type->define( | |||||||||||||||||||||||||||
| 10 | class_name => __PACKAGE__, | ||||||||||||||||||||||||||||
| 11 | is => ['UR::BoolExpr::Template::Composite'], | ||||||||||||||||||||||||||||
| 12 | ); | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 0 | ▶ | sub _flatten_bx { | ||||||||||||||||||||||||||
|
Subroutine
_flatten_bx: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 15 | 0 | my ($class, $bx) = @_; | |||||||||||||||||||||||||||
| 16 | 0 | my @old = $bx->underlying_rules; | |||||||||||||||||||||||||||
| 17 | 0 | my @new; | |||||||||||||||||||||||||||
| 18 | 0 | for my $old (@old) { | |||||||||||||||||||||||||||
| 19 | 0 | my $new = $old->flatten; | |||||||||||||||||||||||||||
| 20 | 0 | push @new, [ $new->_params_list ]; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | 0 | my $flattened_bx = $class->_compose($bx->subject_class_name,\@new); | |||||||||||||||||||||||||||
| 23 | 0 | return $flattened_bx; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 0 | ▶ | sub _reframe_bx { | ||||||||||||||||||||||||||
|
Subroutine
_reframe_bx: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 27 | 0 | my ($class, $bx, $in_terms_of) = @_; | |||||||||||||||||||||||||||
| 28 | 0 | my @old = $bx->underlying_rules; | |||||||||||||||||||||||||||
| 29 | 0 | my @new; | |||||||||||||||||||||||||||
| 30 | 0 | for my $old (@old) { | |||||||||||||||||||||||||||
| 31 | 0 | my $new = $old->reframe($in_terms_of); | |||||||||||||||||||||||||||
| 32 | 0 | push @new, [ $new->_params_list ]; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | 0 | my @meta = $bx->subject_class_name->__meta__->property_meta_for_name($in_terms_of); | |||||||||||||||||||||||||||
| 35 | 0 | my @joins = $meta[-1]->_resolve_join_chain($in_terms_of); | |||||||||||||||||||||||||||
| 36 | 0 | my $reframed_bx = $class->_compose($joins[-1]{foreign_class},\@new); | |||||||||||||||||||||||||||
| 37 | 0 | return $reframed_bx; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub _compose { | ||||||||||||||||||||||||||
|
Subroutine
_compose: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||
| 41 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 42 | 0 | my $subject_class = shift; | |||||||||||||||||||||||||||
| 43 | 0 | my $sub_queries = shift; | |||||||||||||||||||||||||||
| 44 | 0 | my $meta_params = shift; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | my @underlying_rules; | |||||||||||||||||||||||||||
| 47 | my @expressions; | ||||||||||||||||||||||||||||
| 48 | 0 | my @values; | |||||||||||||||||||||||||||
| 49 | 0 | ▶ | while (@$sub_queries) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 0 | my $underlying_query; | |||||||||||||||||||||||||||
| 51 | 0 | ▶ | if (ref($sub_queries->[0]) eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 52 | 0 | $underlying_query = UR::BoolExpr->resolve($subject_class, @{$sub_queries->[0]}, @$meta_params); | |||||||||||||||||||||||||||
| 53 | 0 | shift @$sub_queries; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | elsif (ref($sub_queries->[0]) eq 'UR::BoolExpr::And') { | ||||||||||||||||||||||||||||
| 56 | 0 | $underlying_query = shift @$sub_queries; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | else { | ||||||||||||||||||||||||||||
| 59 | 0 | $underlying_query = UR::BoolExpr->resolve($subject_class, @$sub_queries[0,1], @$meta_params); | |||||||||||||||||||||||||||
| 60 | 0 | shift @$sub_queries; | |||||||||||||||||||||||||||
| 61 | 0 | shift @$sub_queries; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if ($underlying_query->{'_constant_values'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | Carp::confess("cannot use -* expressions in subordinate clauses of a logical <or>"); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | unless ($underlying_query->template->isa("UR::BoolExpr::Template::And")) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 0 | Carp::confess("$underlying_query is not an AND template"); | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | 0 | push @underlying_rules, $underlying_query; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | push @expressions, $underlying_query->template->logic_detail; | |||||||||||||||||||||||||||
| 74 | 0 | push @values, $underlying_query->values; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | 0 | my $bxt = UR::BoolExpr::Template::Or->get_by_subject_class_name_logic_type_and_logic_detail($subject_class,'Or',join('|',@expressions)); | |||||||||||||||||||||||||||
| 77 | 0 | my $bx = $bxt->get_rule_for_values(@values); | |||||||||||||||||||||||||||
| 78 | # This (and accompanying "caching" in UR::BoolExpr::underlying_rules()) | ||||||||||||||||||||||||||||
| 79 | # is a giant hack to allow composite rules to have -order and -group | ||||||||||||||||||||||||||||
| 80 | # The real fix is to coax the above combination of | ||||||||||||||||||||||||||||
| 81 | # get_by_subject_class_name_logic_type_and_logic_detail() and get_rule_for_values() to | ||||||||||||||||||||||||||||
| 82 | # properly encode these constant/template values into the rule and template IDs, | ||||||||||||||||||||||||||||
| 83 | # and subsequently reconsitiute them when you call $template->order_by | ||||||||||||||||||||||||||||
| 84 | 0 | $bx->{'_underlying_rules'} = \@underlying_rules; | |||||||||||||||||||||||||||
| 85 | 0 | ▶ | for (my $i = 0; $i < @$meta_params; $i += 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 0 | my $method = $meta_params->[$i]; | |||||||||||||||||||||||||||
| 87 | 0 | substr($method, 0, 1, ''); # remove the - | |||||||||||||||||||||||||||
| 88 | 0 | ▶ | if ($method eq 'recurse') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 89 | 0 | $bx->template->recursion_desc($meta_params->[$i + 1]); | |||||||||||||||||||||||||||
| 90 | } elsif ($method eq 'order') { | ||||||||||||||||||||||||||||
| 91 | 0 | $bx->template->order_by($meta_params->[$i + 1]); | |||||||||||||||||||||||||||
| 92 | } else { | ||||||||||||||||||||||||||||
| 93 | 0 | $bx->template->$method($meta_params->[$i + 1]); | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | return $bx; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | ▶ | sub _underlying_keys { | ||||||||||||||||||||||||||
|
Subroutine
_underlying_keys: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 101 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 102 | 0 | my $logic_detail = $self->logic_detail; | |||||||||||||||||||||||||||
| 103 | 0 | ▶ | return unless $logic_detail; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 0 | my @underlying_keys = split('\|',$logic_detail); | |||||||||||||||||||||||||||
| 105 | 0 | return @underlying_keys; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | # sub get_underlying_rules_for_values | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | sub get_underlying_rule_templates { | ||||||||||||||||||||||||||
|
Subroutine
get_underlying_rule_templates: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 111 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 112 | 0 | my @underlying_keys = $self->_underlying_keys(); | |||||||||||||||||||||||||||
| 113 | 0 | my $subject_class_name = $self->subject_class_name; | |||||||||||||||||||||||||||
| 114 | return map { | ||||||||||||||||||||||||||||
| 115 | 0 | UR::BoolExpr::Template::And | |||||||||||||||||||||||||||
| 116 | ->_get_for_subject_class_name_and_logic_detail( | ||||||||||||||||||||||||||||
| 117 | $subject_class_name, | ||||||||||||||||||||||||||||
| 118 | $_ | ||||||||||||||||||||||||||||
| 119 | ); | ||||||||||||||||||||||||||||
| 120 | } @underlying_keys; | ||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | sub specifies_value_for { | ||||||||||||||||||||||||||
|
Subroutine
specifies_value_for: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 124 | 0 | my ($self, $property_name) = @_; | |||||||||||||||||||||||||||
| 125 | 0 | ▶ | Carp::confess() if not defined $property_name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 0 | my @underlying_templates = $self->get_underlying_rule_templates(); | |||||||||||||||||||||||||||
| 127 | 0 | my @all_specified; | |||||||||||||||||||||||||||
| 128 | 0 | for my $template (@underlying_templates) { | |||||||||||||||||||||||||||
| 129 | 0 | my @specified = $template->specifies_value_for($property_name); | |||||||||||||||||||||||||||
| 130 | 0 | ▶ | if (@specified) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 0 | push @all_specified, @specified; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | else { | ||||||||||||||||||||||||||||
| 134 | 0 | return; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | 0 | return @all_specified; | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 0 | ▶ | sub evaluate_subject_and_values { | ||||||||||||||||||||||||||
|
Subroutine
evaluate_subject_and_values: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 141 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 142 | 0 | my $subject = shift; | |||||||||||||||||||||||||||
| 143 | 0 | ▶ | return unless (ref($subject) && $subject->isa($self->subject_class_name)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $subject and $subject->isa($self->subject_class_name)
MC/DC0%0/2
ref $subject and $subject->isa($self->subject_class_name)
ref $subject
$subject->isa($self->subject_class_name)
Truth table0%0/3
A and B
A= ref $subjectB= $subject->isa($self->subject_class_name)
| |||||||||||||||||||||||||||||
| 144 | 0 | my @underlying = $self->get_underlying_rule_templates; | |||||||||||||||||||||||||||
| 145 | 0 | ▶ | while (my $underlying = shift (@underlying)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | 0 | my $n = $underlying->_variable_value_count; | |||||||||||||||||||||||||||
| 147 | 0 | my @next_values = splice(@_,0,$n); | |||||||||||||||||||||||||||
| 148 | 0 | ▶ | if ($underlying->evaluate_subject_and_values($subject,@_)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | 0 | return 1; | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | 0 | return; | |||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 0 | ▶ | sub params_list_for_values { | ||||||||||||||||||||||||||
|
Subroutine
params_list_for_values: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 156 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 157 | 0 | my @values_sorted = @_; | |||||||||||||||||||||||||||
| 158 | 0 | my @list; | |||||||||||||||||||||||||||
| 159 | 0 | my @t = $self->get_underlying_rule_templates; | |||||||||||||||||||||||||||
| 160 | 0 | for my $t (@t) { | |||||||||||||||||||||||||||
| 161 | 0 | my $c = $t->_variable_value_count; | |||||||||||||||||||||||||||
| 162 | 0 | my @l = $t->params_list_for_values(splice(@values_sorted,0,$c)); | |||||||||||||||||||||||||||
| 163 | 0 | push @list, \@l; | |||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | 0 | return -or => \@list; | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 0 | ▶ | sub get_normalized_rule_for_values { | ||||||||||||||||||||||||||
|
Subroutine
get_normalized_rule_for_values: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 169 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 170 | 0 | return $self->get_rule_for_values(@_); | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 266 | 1; | |||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | =pod | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | =head1 NAME | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | UR::BoolExpr::Or - a rule which is true if ANY of the underlying conditions are true | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | UR::BoolExpr;(3) | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | =cut | ||||||||||||||||||||||||||||