lib/UR/Object/Type/AccessorWriter.pm

filter: Statementstmt 23.9% 260 / 1084 Branchbran 13.0% 71 / 544 Conditioncond 9.9% 21 / 211 MC/DCmcdc 2.3% 3 / 128 Subroutinesub 37.2% 32 / 86 Podpod 0.0% 0 / 13 totaltotal 18.7% 387 / 2066 CC 1559 SCAR 46.4
CC
1559
Cov
19%
__ANON__
650.0
__ANON__
600.0
_resolve_bridge_logic_for_indirect_property
535.9
CRAP 103.0
« lib/UR/Context/Transaction.pm ↑ Summary lib/UR/Object/Type/InternalAPI.pm »
1  
2 package UR::Object::Type::AccessorWriter;
3  
4 package UR::Object::Type;
5  
6 266 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 266 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 266 require UR;
9 266 our $VERSION = "0.47"; # UR $VERSION;
10 #use warnings FATAL => 'all';
11  
12 266 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 266 ▶use Sub::Name ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 266 ▶use Sub::Install ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 266 ▶use List::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 30054 ▶sub mk_rw_accessor {
Subroutine mk_rw_accessor: called CC=3 SCAR=13.5
Pod undocumented
18 30054 my ($self, $class_name, $accessor_name, $column_name, $property_name, $is_transient) = @_;
19 30054 ▶ $property_name ||= $accessor_name;
Condition33%1/3
$property_name ||= $accessor_name
l!l&&r!l&&!r
3005400
MC/DC0%0/2
$property_name ||= $accessor_name
$property_name $accessor_name
Truth table33%1/3
A ||= B
A= $property_nameB= $accessor_name
ABresult
1X1
011
000
20  
21 30054 my $full_name = join( '::', $class_name, $accessor_name );
22 116 ▶ my $accessor = Sub::Name::subname $full_name => sub {
Subroutine valid_signals: called CC=5 SCAR=21.8
Subroutine priority: called CC=5 SCAR=21.8
23 116 ▶ if (@_ > 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ > 1) 0 116 116
if (@_ > 1) 0 9611 9611
24 0 my $old = $_[0]->{ $property_name };
25 0 my $new = $_[1];
26  
27 # The accessors may compare undef and an empty
28 # string. For speed, we turn warnings off rather
29 # than add extra code to make the warning disappear.
30 0 local $@;
31 0 ▶ my $different = eval { no warnings; $old ne $new };
Subroutine BEGIN: called CC=1 SCAR=0.2
32 0 ▶ if ($different or $@ =~ m/has no overloaded magic/)
Branch: 2 branches
BranchTrueFalseTotal
if ($different or $@ =~ /has no overloaded magic/) 0 0 0
if ($different or $@ =~ /has no overloaded magic/) 186 0 186
Condition16%1/6
$different or $@ =~ /has no overloaded magic/
l!l&&r!l&&!r
000
$different or $@ =~ /has no overloaded magic/
l!l&&r!l&&!r
18600
MC/DC0%0/2
$different or $@ =~ /has no overloaded magic/
$different $@ =~ /has no overloaded magic/
MC/DC0%0/2
$different or $@ =~ /has no overloaded magic/
$different $@ =~ /has no overloaded magic/
Truth table0%0/3
A or B
A= $differentB= $@ =~ /has no overloaded magic/
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $differentB= $@ =~ /has no overloaded magic/
ABresult
1X1
011
000
33 {
34 0 $_[0]->{ $property_name } = $new;
35 0 ▶ $_[0]->__signal_change__( $property_name, $old, $new ) unless $is_transient; # FIXME is $is_transient right here? Maybe is_volatile instead (if at all)?
Branch: 2 branches
BranchTrueFalseTotal
unless $is_transient 0 0 0
unless $is_transient 0 186 186
36 }
37 0 return $new;
38 }
39 116 $_[0]->{ $property_name }
40 30054 };
41  
42 30054 ▶ if (_class_is_singleton($class_name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_class_is_singleton($class_name)) 798 29256 30054
43 798 my $basic_accessor = $accessor;
44 0 ▶ $accessor = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
45 0 shift->_singleton_object->$basic_accessor(@_);
46 798 };
47 }
48  
49 Sub::Install::reinstall_sub({
50 30054 into => $class_name,
51 as => $accessor_name,
52 code => $accessor,
53 });
54  
55 }
56  
57 4522 ▶sub mk_ro_accessor {
Subroutine mk_ro_accessor: called CC=3 SCAR=16.7
Pod undocumented
58 4522 my ($self, $class_name, $accessor_name, $column_name, $property_name) = @_;
59 4522 ▶ $property_name ||= $accessor_name;
Condition33%1/3
$property_name ||= $accessor_name
l!l&&r!l&&!r
452200
MC/DC0%0/2
$property_name ||= $accessor_name
$property_name $accessor_name
Truth table33%1/3
A ||= B
A= $property_nameB= $accessor_name
ABresult
1X1
011
000
60  
61 4522 my $full_name = join( '::', $class_name, $accessor_name );
62 13863 ▶ my $accessor = Sub::Name::subname $full_name => sub {
Subroutine __id: called CC=4 SCAR=23.3
63 0 ▶ if (@_ > 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ > 1) 0 13863 13863
if (@_ > 1) 0 186 186
64 0 my $old = $_[0]->{ $property_name};
65 0 my $new = $_[1];
66  
67 0 my $different;
68 0 my $exception = do {
69 0 local $@;
70 0 ▶ $different = eval { no warnings; $old ne $new };
Subroutine BEGIN: called CC=1 SCAR=0.6
71 0 $@;
72 };
73 0 ▶ if ($different or $exception =~ m/has no overloaded magic/)
Branch: 1 branch
BranchTrueFalseTotal
if ($different or $exception =~ /has no overloaded magic/) 0 0 0
Condition0%0/6
$different or $exception =~ /has no overloaded magic/
l!l&&r!l&&!r
000
$different or $exception =~ /has no overloaded magic/
l!l&&r!l&&!r
000
MC/DC0%0/2
$different or $exception =~ /has no overloaded magic/
$different $exception =~ /has no overloaded magic/
MC/DC0%0/2
$different or $exception =~ /has no overloaded magic/
$different $exception =~ /has no overloaded magic/
Truth table0%0/3
A or B
A= $differentB= $exception =~ /has no overloaded magic/
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $differentB= $exception =~ /has no overloaded magic/
ABresult
1X1
011
000
74 {
75 0 Carp::croak("Cannot change read-only property $accessor_name for class $class_name!"
76 . " Failed to update " . $_[0]->__display_name__ . " property: $property_name from $old to $new");
77 }
78 0 return $new;
79 }
80 13863 return $_[0]->{ $property_name };
81 4522 };
82  
83 4522 ▶ if (_class_is_singleton($class_name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_class_is_singleton($class_name)) 0 4522 4522
84 0 my $basic_accessor = $accessor;
85 0 ▶ $accessor = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
86 0 shift->_singleton_object->$basic_accessor(@_);
87 0 };
88 }
89  
90 Sub::Install::reinstall_sub({
91 4522 into => $class_name,
92 as => $accessor_name,
93 code => $accessor,
94 });
95  
96 }
97  
98 34576 ▶sub _class_is_singleton {
Subroutine _class_is_singleton: called CC=1 SCAR=0.0
99 34576 my $class_name = shift;
100 34576 return grep { $_->isa('UR::Singleton') } @{ $class_name->__meta__->{is} };
101 }
102  
103 0 ▶sub mk_id_based_flex_accessor {
Subroutine mk_id_based_flex_accessor: not called CC=2 SCAR=17.9
Pod undocumented
104 0 my ($self, $class_name, $accessor_name, $id_by, $r_class_name, $where, $id_class_by) = @_;
105  
106 0 ▶ unless (ref($id_by)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $id_by) 0 0 0
107 0 $id_by = [ $id_by ];
108 }
109  
110 0 my $id_resolver;
111 my $id_decomposer;
112 0 my @id;
113 0 my $id;
114 0 my $full_name = join( '::', $class_name, $accessor_name );
115 0 my $concrete_r_class_name = $r_class_name;
116 0 ▶ my $accessor = Sub::Name::subname $full_name => sub {
Subroutine __ANON__: not called CC=25 SCAR=64.8
117 0 my $self = shift;
118 0 ▶ if (@_ == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 0 0 0
119 # This one is to support syntax like this
120 # $cd->artist($different_artist);
121 # to switch which artist object this cd points to
122 0 my $object_value = shift;
123 0 ▶ if ($id_class_by and not ref $object_value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id_class_by and not ref $object_value) 0 0 0
Condition0%0/3
$id_class_by and not ref $object_value
!ll&&!rl&&r
000
MC/DC0%0/2
$id_class_by and not ref $object_value
$id_class_by not ref $object_value
Truth table0%0/3
A and not(B)
A= $id_class_byB= not ref $object_value
ABresult
0X0
100
111
124 # when we have an id-class-by accessor and get a primitive, store it as a UR::Value
125 0 $object_value = UR::Value->get($object_value);
126 }
127 0 ▶ if (defined $object_value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $object_value) { } 0 0 0
128 0 ▶ if ($id_class_by) {
Branch: 2 branches
BranchTrueFalseTotal
if ($id_class_by) { } 0 0 0
elsif (not builtin::blessed($object_value) || $object_value->can('id')) { } 0 0 0
129 0 ▶ $concrete_r_class_name = ($object_value->can('class') ? $object_value->class : ref($object_value));
Branch: 1 branch
BranchTrueFalseTotal
$object_value->can('class') ? : 0 0 0
130 0 $id_decomposer = undef;
131 0 $id_resolver = undef;
132 0 $self->$id_class_by($concrete_r_class_name);
133 ▶ } elsif (! Scalar::Util::blessed($object_value) and ! $object_value->can('id')) {
Condition0%0/3
builtin::blessed($object_value) || $object_value->can('id')
l!l&&r!l&&!r
000
MC/DC0%0/2
builtin::blessed($object_value) || $object_value->can('id')
builtin::blessed($object_value) $object_value->can('id')
Truth table0%0/3
A || B
A= builtin::blessed($object_value)B= $object_value->can('id')
ABresult
1X1
011
000
134 0 Carp::croak("Can't call method \"id\" without a package or object reference. Expected an object as parameter to '$accessor_name', not the value '$object_value'");
135 }
136  
137 0 my $r_class_meta = do {
138 0 local $@;
139 0 eval { $concrete_r_class_name->__meta__ };
140 };
141 0 ▶ unless ($r_class_meta) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r_class_meta) 0 0 0
142 0 Carp::croak("Can't get metadata for class $concrete_r_class_name. Is it a UR class?");
143 }
144  
145 0 ▶ $id_decomposer ||= $r_class_meta->get_composite_id_decomposer;
Condition0%0/3
$id_decomposer ||= $r_class_meta->get_composite_id_decomposer
l!l&&r!l&&!r
000
MC/DC0%0/2
$id_decomposer ||= $r_class_meta->get_composite_id_decomposer
$id_decomposer $r_class_meta->get_composite_id_decomposer
Truth table0%0/3
A ||= B
A= $id_decomposerB= $r_class_meta->get_composite_id_decomposer
ABresult
1X1
011
000
146 0 @id = $id_decomposer->($object_value->id);
147 0 ▶ if (@$id_by == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$id_by == 1) { } 0 0 0
148 0 my $id_property_name = $id_by->[0];
149 0 $self->$id_property_name($object_value->id);
150 } else {
151 0 @id = $id_decomposer->($object_value->id);
152 0 Carp::croak("Cannot alter value for '$accessor_name' on $class_name: The passed-in object of type "
153 . $object_value->class . " has " . scalar(@id) . " id properties, but the accessor '$accessor_name' has "
154 . scalar(@$id_by) . " id_by properties");
155 0 for my $id_property_name (@$id_by) {
156 0 $self->$id_property_name(shift @id);
157 }
158 }
159 }
160 else {
161 0 ▶ if ($id_class_by) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id_class_by) 0 0 0
162 0 $self->$id_class_by(undef);
163 }
164 0 for my $id_property_name (@$id_by) {
165 0 $self->$id_property_name(undef);
166 }
167 }
168 0 return $object_value;
169 }
170 else {
171 0 ▶ if ($id_class_by) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id_class_by) 0 0 0
172 0 $concrete_r_class_name = $self->$id_class_by;
173 0 $id_decomposer = undef;
174 0 $id_resolver = undef;
175 0 ▶ return unless $concrete_r_class_name;
Branch: 1 branch
BranchTrueFalseTotal
unless $concrete_r_class_name 0 0 0
176 }
177 0 ▶ unless ($id_resolver) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($id_resolver) 0 0 0
178 0 my $concrete_r_class_meta = UR::Object::Type->get($concrete_r_class_name);
179 0 ▶ unless ($concrete_r_class_meta) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($concrete_r_class_meta) 0 0 0
180 0 Carp::croak("Can't resolve value for '$accessor_name' on class $class_name id '".$self->id
181 . "': No class metadata for value '$concrete_r_class_name' referenced as property '$id_class_by'");
182 }
183 0 $id_resolver = $concrete_r_class_meta->get_composite_id_resolver;
184 }
185  
186 # eliminate the old map{} because of side effects with $_
187 # when the id_by property happens to be calculated
188 #@id = map { $self->$_ } @$id_by;
189 0 @id=();
190 0 for my $property_name (@$id_by) { # no implicit topic
191 0 my $value = $self->$property_name; # scalar context
192 0 push @id, $value;
193 }
194  
195 0 $id = $id_resolver->(@id);
196 0 ▶ return if not defined $id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id 0 0 0
197 0 ▶ if ($concrete_r_class_name eq 'UR::Object') {
Branch: 1 branch
BranchTrueFalseTotal
if ($concrete_r_class_name eq "UR::Object") 0 0 0
198 0 Carp::carp("Querying by using UR::Object class is deprecated.");
199 }
200  
201 0 ▶ if ($concrete_r_class_name->isa("UR::Value")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($concrete_r_class_name->isa('UR::Value')) { } 0 0 0
202 0 return $id;
203 }
204 else {
205 0 ▶ if (@_ || $where) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ or $where) { } 0 0 0
Condition0%0/3
@_ or $where
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ or $where
@_ $where
Truth table0%0/3
A or B
A= @_B= $where
ABresult
1X1
011
000
206 # There were additional params passed in
207 0 return $concrete_r_class_name->get(id => $id, @_, @$where);
208 } else {
209 0 return $concrete_r_class_name->get($id);
210 }
211 }
212 }
213 0 };
214  
215 0 Sub::Install::reinstall_sub({
216 into => $class_name,
217 as => $accessor_name,
218 code => $accessor,
219 });
220 }
221  
222 2128 ▶sub mk_id_based_object_accessor {
Subroutine mk_id_based_object_accessor: called CC=2 SCAR=11.5
Pod undocumented
223 2128 my ($self, $class_name, $accessor_name, $id_by, $r_class_name, $where, $id_class_by) = @_;
224  
225 2128 ▶ unless (ref($id_by)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $id_by) 0 2128 2128
226 0 $id_by = [ $id_by ];
227 }
228  
229 2128 my $id_resolver;
230 my $id_decomposer;
231 2128 my @id;
232 2128 my $id;
233 2128 my $full_name = join( '::', $class_name, $accessor_name );
234 2128 my $concrete_r_class_name = $r_class_name;
235 532 ▶ my $accessor = Sub::Name::subname $full_name => sub {
Subroutine namespace_meta: called CC=23 SCAR=54.2
236 532 my $self = shift;
237 532 ▶ if (@_ == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 0 532 532
238 # This one is to support syntax like this
239 # $cd->artist($different_artist);
240 # to switch which artist object this cd points to
241 0 my $object_value = shift;
242 0 ▶ if (defined $object_value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $object_value) { } 0 0 0
243 0 ▶ if ($id_class_by) {
Branch: 2 branches
BranchTrueFalseTotal
if ($id_class_by) { } 0 0 0
elsif (not builtin::blessed($object_value) || $object_value->can('id')) { } 0 0 0
244 0 ▶ $concrete_r_class_name = ($object_value->can('class') ? $object_value->class : ref($object_value));
Branch: 1 branch
BranchTrueFalseTotal
$object_value->can('class') ? : 0 0 0
245 0 $id_decomposer = undef;
246 0 $id_resolver = undef;
247 0 $self->$id_class_by($concrete_r_class_name);
248 ▶ } elsif (! Scalar::Util::blessed($object_value) and ! $object_value->can('id')) {
Condition0%0/6
builtin::blessed($object_value) || $object_value->can('id')
l!l&&r!l&&!r
000
builtin::blessed($object_value) || $object_value->can('id')
l!l&&r!l&&!r
000
MC/DC0%0/2
builtin::blessed($object_value) || $object_value->can('id')
builtin::blessed($object_value) $object_value->can('id')
MC/DC0%0/2
builtin::blessed($object_value) || $object_value->can('id')
builtin::blessed($object_value) $object_value->can('id')
Truth table0%0/3
A || B
A= builtin::blessed($object_value)B= $object_value->can('id')
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= builtin::blessed($object_value)B= $object_value->can('id')
ABresult
1X1
011
000
249 0 Carp::croak("Can't call method \"id\" without a package or object reference. Expected an object as parameter to '$accessor_name', not the value '$object_value'");
250 }
251  
252 0 my $r_class_meta = do {
253 0 local $@;
254 0 eval { $concrete_r_class_name->__meta__ };
255 };
256 0 ▶ unless ($r_class_meta) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r_class_meta) 0 0 0
257 0 Carp::croak("Can't get metadata for class $concrete_r_class_name. Is it a UR class?");
258 }
259  
260 0 ▶ $id_decomposer ||= $r_class_meta->get_composite_id_decomposer;
Condition0%0/3
$id_decomposer ||= $r_class_meta->get_composite_id_decomposer
l!l&&r!l&&!r
000
MC/DC0%0/2
$id_decomposer ||= $r_class_meta->get_composite_id_decomposer
$id_decomposer $r_class_meta->get_composite_id_decomposer
Truth table0%0/3
A ||= B
A= $id_decomposerB= $r_class_meta->get_composite_id_decomposer
ABresult
1X1
011
000
261 0 @id = $id_decomposer->($object_value->id);
262 0 ▶ if (@$id_by == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$id_by == 1) { } 0 0 0
263 0 my $id_property_name = $id_by->[0];
264 0 $self->$id_property_name($object_value->id);
265 } else {
266 0 @id = $id_decomposer->($object_value->id);
267 0 Carp::croak("Cannot alter value for '$accessor_name' on $class_name: The passed-in object of type "
268 . $object_value->class . " has " . scalar(@id) . " id properties, but the accessor '$accessor_name' has "
269 . scalar(@$id_by) . " id_by properties");
270 0 for my $id_property_name (@$id_by) {
271 0 $self->$id_property_name(shift @id);
272 }
273 }
274 }
275 else {
276 0 ▶ if ($id_class_by) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id_class_by) 0 0 0
277 0 $self->$id_class_by(undef);
278 }
279 0 for my $id_property_name (@$id_by) {
280 0 $self->$id_property_name(undef);
281 }
282 }
283 0 return $object_value;
284 }
285 else {
286 532 ▶ if ($id_class_by) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id_class_by) 0 532 532
287 0 $concrete_r_class_name = $self->$id_class_by;
288 0 $id_decomposer = undef;
289 0 $id_resolver = undef;
290 0 ▶ return unless $concrete_r_class_name;
Branch: 1 branch
BranchTrueFalseTotal
unless $concrete_r_class_name 0 0 0
291 }
292 532 ▶ unless ($id_resolver) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($id_resolver) 266 266 532
293 266 my $concrete_r_class_meta = UR::Object::Type->get($concrete_r_class_name);
294 266 ▶ unless ($concrete_r_class_meta) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($concrete_r_class_meta) 0 266 266
295 0 Carp::croak("Can't resolve value for '$accessor_name' on class $class_name id '".$self->id
296 . "': No class metadata for value '$concrete_r_class_name' referenced as property '$id_class_by'");
297 }
298 266 $id_resolver = $concrete_r_class_meta->get_composite_id_resolver;
299 }
300  
301 532 @id=();
302 532 for my $property_name (@$id_by) { # no implicit topic
303 532 my $value = $self->$property_name; # scalar context
304 532 push @id, $value;
305 }
306  
307 532 ▶ $id = @id > 1
Branch: 1 branch
BranchTrueFalseTotal
@id > 1 ? : 0 532 532
308 ? $id_resolver->(@id)
309 : $id[0];
310  
311 532 ▶ return if not defined $id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id 0 532 532
312 532 ▶ if ($concrete_r_class_name eq 'UR::Object') {
Branch: 1 branch
BranchTrueFalseTotal
if ($concrete_r_class_name eq "UR::Object") 0 532 532
313 0 Carp::carp("Querying by using UR::Object class is deprecated.");
314 }
315 532 ▶ if (@_ || $where) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ or $where) { } 0 532 532
Condition33%1/3
@_ or $where
l!l&&r!l&&!r
00532
MC/DC0%0/2
@_ or $where
@_ $where
Truth table33%1/3
A or B
A= @_B= $where
ABresult
1X1
011
000
316 # There were additional params passed in
317 0 return $concrete_r_class_name->get(id => $id, @_, @$where);
318 } else {
319 532 return $concrete_r_class_name->get($id);
320 }
321 }
322 2128 };
323  
324 2128 Sub::Install::reinstall_sub({
325 into => $class_name,
326 as => $accessor_name,
327 code => $accessor,
328 });
329 }
330  
331  
332 798 ▶sub _resolve_bridge_logic_for_indirect_property {
Subroutine _resolve_bridge_logic_for_indirect_property: called CC=27 SCAR=62.8
333 798 my ($ur_object_type, $class_name, $accessor_name, $via, $to, $where) = @_;
334  
335 798 ▶ my $bridge_collector = sub {
Subroutine __ANON__: called CC=3 SCAR=12.0
336 798 my $self = shift;
337 798 my @results = $self->$via(@$where);
338 # Indirect has one properties must return a single undef value for an empty result, even in list context.
339 798 ▶ return if @results == 1 and not defined $results[0];
Branch: 1 branch
BranchTrueFalseTotal
if @results == 1 and not defined $results[0] 0 798 798
Condition33%1/3
@results == 1 and not defined $results[0]
!ll&&!rl&&r
07980
MC/DC0%0/2
@results == 1 and not defined $results[0]
@results == 1 not defined $results[0]
Truth table33%1/3
A and not(B)
A= @results == 1B= not defined $results[0]
ABresult
0X0
100
111
340 798 return @results;
341 798 };
342 798 ▶ my $bridge_crosser = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
343 798 my $bridges = shift;
344 798 return map { $_->$to(@_) } @$bridges;
345 798 };
346  
347 798 ▶ return($bridge_collector, $bridge_crosser) if ($UR::Object::Type::bootstrapping);
Branch: 1 branch
BranchTrueFalseTotal
if $UR::Object::Type::bootstrapping 798 0 798
348  
349 # bail out and use the default subs if any of these fail
350 0 my ($my_class_meta, $my_property_meta, $via_property_meta, $to_property_meta);
351  
352 0 $my_class_meta = $class_name->__meta__;
353 0 ▶ $my_property_meta = $my_class_meta->property_meta_for_name($accessor_name) if ($my_class_meta);
Branch: 1 branch
BranchTrueFalseTotal
if $my_class_meta 0 0 0
354 0 ▶ $via_property_meta = $my_class_meta->property_meta_for_name($via) if ($my_class_meta);
Branch: 1 branch
BranchTrueFalseTotal
if $my_class_meta 0 0 0
355 0 ▶ $to_property_meta = $my_property_meta->to_property_meta() if ($my_property_meta);
Branch: 1 branch
BranchTrueFalseTotal
if $my_property_meta 0 0 0
356  
357 0 ▶ if (! $my_class_meta || ! $my_property_meta || ! $via_property_meta || ! $to_property_meta) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($my_class_meta and $my_property_meta and $via_property_meta and $to_property_meta) 0 0 0
Condition0%0/9
$my_class_meta and $my_property_meta and $via_property_meta and $to_property_meta
!ll&&!rl&&r
000
$my_class_meta and $my_property_meta and $via_property_meta
!ll&&!rl&&r
000
$my_class_meta and $my_property_meta
!ll&&!rl&&r
000
MC/DC0%0/4
$my_class_meta and $my_property_meta and $via_property_meta and $to_property_meta
$my_class_meta $my_property_meta $via_property_meta $to_property_meta
Truth table0%0/5
A and B and C and D
A= $my_class_metaB= $my_property_metaC= $via_property_metaD= $to_property_meta
ABCDresult
0XXX0
10XX0
110X0
11100
11111
358 # Something didn't link right, use the default methods
359 0 return ($bridge_collector, $bridge_crosser);
360 }
361  
362 0 ▶ if ($my_property_meta->is_delegated and $my_property_meta->is_many
Branch: 1 branch
BranchTrueFalseTotal
if ($my_property_meta->is_delegated and $my_property_meta->is_many and $via_property_meta->is_many and $via_property_meta->reverse_as and $via_property_meta->data_type and $via_property_meta->data_type->isa("UR::Object")) 0 0 0
Condition0%0/15
$my_property_meta->is_delegated and $my_property_meta->is_many and $via_property_meta->is_many and $via_property_meta->reverse_as and $via_property_meta->data_type and $via_property_meta->data_type->isa("UR::Object")
!ll&&!rl&&r
000
$my_property_meta->is_delegated and $my_property_meta->is_many and $via_property_meta->is_many and $via_property_meta->reverse_as and $via_property_meta->data_type
!ll&&!rl&&r
000
$my_property_meta->is_delegated and $my_property_meta->is_many and $via_property_meta->is_many and $via_property_meta->reverse_as
!ll&&!rl&&r
000
$my_property_meta->is_delegated and $my_property_meta->is_many and $via_property_meta->is_many
!ll&&!rl&&r
000
$my_property_meta->is_delegated and $my_property_meta->is_many
!ll&&!rl&&r
000
MC/DC0%0/6
$my_property_meta->is_delegated and $my_property_meta->is_many and $via_property_meta->is_many and $via_property_meta->reverse_as and $via_property_meta->data_type and $via_property_meta->data_type->isa("UR::Object")
$my_property_meta->is_delegated $my_property_meta->is_many $via_property_meta->is_many $via_property_meta->reverse_as $via_property_meta->data_type $via_property_meta->data_type->isa("UR::Object")
Truth table0%0/7
A and B and C and D and E and F
A= $my_property_meta->is_delegatedB= $my_property_meta->is_manyC= $via_property_meta->is_manyD= $via_property_meta->reverse_asE= $via_property_meta->data_typeF= $via_property_meta->data_type->isa("UR::Object")
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
363 and $via_property_meta->is_many and $via_property_meta->reverse_as
364 and $via_property_meta->data_type and $via_property_meta->data_type->isa('UR::Object')
365 ) {
366 0 my $bridge_class = $via_property_meta->data_type;
367  
368 0 my @via_join_properties = do {
369 0 local $@;
370 0 eval { $via_property_meta->get_property_name_pairs_for_join };
371 };
372 0 ▶ if (! @via_join_properties) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@via_join_properties) 0 0 0
373 # this can happen if the properties aren't linked together as expected.
374 # For example, a property involved in a many-to-many relationship, but is
375 # defined as a one-to-many with reverse_as.
376 0 return ($bridge_collector, $bridge_crosser);
377 }
378  
379 0 my (@my_join_properties,@their_join_properties);
380 0 ▶ for (my $i = 0; $i < @via_join_properties; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @via_join_properties) 0 0 0
381 0 ($my_join_properties[$i], $their_join_properties[$i]) = @{ $via_join_properties[$i] };
382 }
383  
384 0 my(@where_properties, @where_values, %bridge_meta_params);
385 0 ▶ if ($where or $via_property_meta->where) {
Branch: 1 branch
BranchTrueFalseTotal
if ($where or $via_property_meta->where) 0 0 0
Condition0%0/3
$where or $via_property_meta->where
l!l&&r!l&&!r
000
MC/DC0%0/2
$where or $via_property_meta->where
$where $via_property_meta->where
Truth table0%0/3
A or B
A= $whereB= $via_property_meta->where
ABresult
1X1
011
000
386 0 my @collected_where;
387 0 ▶ @collected_where = @$where if ($where);
Branch: 1 branch
BranchTrueFalseTotal
if $where 0 0 0
388 0 ▶ push @collected_where, @{ $via_property_meta->where } if ($via_property_meta->where);
Branch: 1 branch
BranchTrueFalseTotal
if $via_property_meta->where 0 0 0
389 0 ▶ while (@collected_where) {
Branch: 1 branch
BranchTrueFalseTotal
if (@collected_where) 0 0 0
390 0 my $where_property = shift @collected_where;
391 0 my $where_value = shift @collected_where;
392  
393 0 ▶ if (UR::BoolExpr::Util::is_meta_param($where_property)) {
Branch: 1 branch
BranchTrueFalseTotal
if (UR::BoolExpr::Util::is_meta_param($where_property)) { } 0 0 0
394 0 $bridge_meta_params{$where_property} = $where_value;
395  
396 } else {
397 0 ▶ if (ref($where_value) eq 'HASH' and $where_value->{'operator'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $where_value eq "HASH" and $where_value->{"operator"}) 0 0 0
Condition0%0/3
ref $where_value eq "HASH" and $where_value->{"operator"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $where_value eq "HASH" and $where_value->{"operator"}
ref $where_value eq "HASH" $where_value->{"operator"}
Truth table0%0/3
A and B
A= ref $where_value eq "HASH"B= $where_value->{"operator"}
ABresult
0X0
100
111
398 0 $where_property .= ' ' .$where_value->{'operator'};
399 0 $where_value = $where_value->{'value'};
400 }
401 0 push @where_properties, $where_property;
402 0 push @where_values, $where_value;
403 }
404 }
405 }
406  
407 0 my $bridge_template = UR::BoolExpr::Template->resolve($bridge_class, @their_join_properties, @where_properties, %bridge_meta_params);
408  
409 0 ▶ $bridge_collector = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
410 0 my $self = shift;
411 0 my @my_values = map { $self->$_} @my_join_properties;
412 0 my $bx = $bridge_template->get_rule_for_values(@my_values, @where_values);
413 0 return $bridge_class->get($bx);
414 0 };
415  
416 0 ▶ if ($to_property_meta->is_delegated
Branch: 1 branch
BranchTrueFalseTotal
if ($to_property_meta->is_delegated and my $doubly_deledated_bridge_crosser = _resolve_bridge_crosser_for_doubly_delegated_property($to_property_meta, \%bridge_meta_params)) 0 0 0
Condition0%0/3
$to_property_meta->is_delegated and my $doubly_deledated_bridge_crosser = _resolve_bridge_crosser_for_doubly_delegated_property($to_property_meta, \%bridge_meta_params)
!ll&&!rl&&r
000
MC/DC0%0/2
$to_property_meta->is_delegated and my $doubly_deledated_bridge_crosser = _resolve_bridge_crosser_for_doubly_delegated_property($to_property_meta, \%bridge_meta_params)
$to_property_meta->is_delegated my $doubly_deledated_bridge_crosser = _resolve_bridge_crosser_for_doubly_delegated_property($to_property_meta, \%bridge_meta_params)
Truth table0%0/3
A and B
A= $to_property_meta->is_delegatedB= my $doubly_deledated_bridge_crosser = _resolve_bridge_crosser_for_doubly_delegated_property($to_property_meta, \%bridge_meta_params)
ABresult
0X0
100
111
417 and
418 my $doubly_deledated_bridge_crosser = _resolve_bridge_crosser_for_doubly_delegated_property($to_property_meta, \%bridge_meta_params)
419 ) {
420 0 $bridge_crosser = $doubly_deledated_bridge_crosser;
421 }
422 }
423 0 return ($bridge_collector, $bridge_crosser);
424 }
425  
426 0 ▶sub _make_results_sorter_for_doubly_delegated_bridge_crosser {
Subroutine _make_results_sorter_for_doubly_delegated_bridge_crosser: not called CC=1 SCAR=6.9
427 0 my($bridges, $bridge_linker, $results_linker) = @_;
428  
429 0 my $rank = 0;
430 0 my %bridge_rankings = map { $bridge_linker->() => $rank++ } @$bridges;
431 0 ▶ return sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
432 0 my $results = shift;
433  
434 0 return map { $_->[1] }
435 0 sort { $bridge_rankings{ $a->[0] } <=> $bridge_rankings{ $b->[0] } }
436 0 map { [ $results_linker->(), $_ ] }
437 @$results;
438 0 };
439 }
440  
441 0 ▶sub _resolve_bridge_crosser_for_doubly_delegated_property {
Subroutine _resolve_bridge_crosser_for_doubly_delegated_property: not called CC=11 SCAR=48.8
442 0 my($to_property_meta, $bridge_meta_params) = @_;
443 # This property's value is doubly delegated. The simple thing to
444 # do is to collect the bridge objects, then call the second
445 # delegation method on each bridge in a loop to collect the final
446 # results, which may trigger one query per result. Depending on
447 # the type of delegation, the final results can be collected with
448 # one query
449  
450 0 my($result_class_resolver, $bridge_linking_properties, $final_result_property_name, $result_filtering_property);
451 0 ▶ if ($to_property_meta->via) {
Branch: 3 branches
BranchTrueFalseTotal
if ($to_property_meta->via) { } 0 0 0
elsif ($to_property_meta->id_by) { } 0 0 0
elsif ($to_property_meta->reverse_as) { } 0 0 0
452 # bridges through another via-to property
453 0 my $second_via_property_meta = $to_property_meta->via_property_meta;
454 0 my $final_class_name = $second_via_property_meta->data_type;
455 0 ▶ if ($final_class_name and $final_class_name ne 'UR::Value' and $final_class_name->isa('UR::Object')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($final_class_name and $final_class_name ne "UR::Value" and $final_class_name->isa("UR::Object")) 0 0 0
Condition0%0/6
$final_class_name and $final_class_name ne "UR::Value" and $final_class_name->isa("UR::Object")
!ll&&!rl&&r
000
$final_class_name and $final_class_name ne "UR::Value"
!ll&&!rl&&r
000
MC/DC0%0/3
$final_class_name and $final_class_name ne "UR::Value" and $final_class_name->isa("UR::Object")
$final_class_name $final_class_name ne "UR::Value" $final_class_name->isa("UR::Object")
Truth table0%0/4
A and B and C
A= $final_class_nameB= $final_class_name ne "UR::Value"C= $final_class_name->isa("UR::Object")
ABCresult
0XX0
10X0
1100
1111
456 0 ▶ if ( 1 == (my @via2_join_properties = $second_via_property_meta->get_property_name_pairs_for_join)) {
Branch: 1 branch
BranchTrueFalseTotal
if (1 == (my(@via2_join_properties) = $second_via_property_meta->get_property_name_pairs_for_join)) 0 0 0
457 0 $bridge_linking_properties = [ $via2_join_properties[0]->[0] ];
458 0 $result_filtering_property = $via2_join_properties[0]->[1];
459 0 ▶ $result_class_resolver = sub { $final_class_name };
Subroutine __ANON__: not called CC=1 SCAR=6.9
460  
461 0 $final_result_property_name = $to_property_meta->to;
462 }
463 }
464  
465 } elsif ($to_property_meta->id_by) {
466 0 $bridge_linking_properties = $to_property_meta->id_by;
467 0 $result_filtering_property = 'id';
468 0 ▶ if ($to_property_meta->id_class_by) {
Branch: 1 branch
BranchTrueFalseTotal
if ($to_property_meta->id_class_by) { } 0 0 0
469 # Bridging through an 'id_class_by' property
470 # bucket the bridge items by the result class and do a get for
471 # each of those classes with a listref of IDs
472 0 my $result_class_resolving_property = $to_property_meta->id_class_by;
473 0 ▶ $result_class_resolver = sub { shift->$result_class_resolving_property };
Subroutine __ANON__: not called CC=1 SCAR=6.9
474  
475 } else {
476 # Bridging through a regular id-by property
477 0 my $result_class = $to_property_meta->data_type;
478 0 ▶ $result_class_resolver = sub { $result_class };
Subroutine __ANON__: not called CC=1 SCAR=6.9
479 }
480  
481 } elsif ($to_property_meta->reverse_as) {
482 0 ▶ if (1 == (my @reverse_as_join_properties = $to_property_meta->get_property_name_pairs_for_join)) {
Branch: 1 branch
BranchTrueFalseTotal
if (1 == (my(@reverse_as_join_properties) = $to_property_meta->get_property_name_pairs_for_join)) 0 0 0
483 0 $bridge_linking_properties = [ map { $_->[0] } @reverse_as_join_properties ];
484 0 $result_filtering_property = $reverse_as_join_properties[0]->[1];
485  
486 0 my $result_class = $to_property_meta->data_type;
487 0 ▶ $result_class_resolver = sub { $result_class };
Subroutine __ANON__: not called CC=1 SCAR=6.9
488 }
489 }
490  
491 0 ▶ if ($result_class_resolver) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result_class_resolver) 0 0 0
492 0 my $linking_id_value_for_bridge = do {
493 0 my %composite_id_resolver_for_class;
494  
495 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
496 0 my $bridge = shift;
497 0 my @id = map { $bridge->$_ } @$bridge_linking_properties;
498  
499 0 my $result_class = $result_class_resolver->($bridge);
500 0 ▶ my $id_resolver = $composite_id_resolver_for_class{ $result_class }
Condition0%0/3
$composite_id_resolver_for_class{$result_class} ||= $result_class->__meta__->get_composite_id_resolver
l!l&&r!l&&!r
000
MC/DC0%0/2
$composite_id_resolver_for_class{$result_class} ||= $result_class->__meta__->get_composite_id_resolver
$composite_id_resolver_for_class{$result_class} $result_class->__meta__->get_composite_id_resolver
Truth table0%0/3
A ||= B
A= $composite_id_resolver_for_class{$result_class}B= $result_class->__meta__->get_composite_id_resolver
ABresult
1X1
011
000
501 ||= $result_class->__meta__->get_composite_id_resolver;
502  
503 0 return $id_resolver->(@id);
504 0 };
505 };
506  
507 0 ▶ return sub {
Subroutine __ANON__: not called CC=8 SCAR=42.8
508 0 my $bridges = shift;
509 0 my %result_class_names_and_ids;
510  
511 0 foreach my $bridge ( @$bridges ) {
512 0 my $result_class = $result_class_resolver->($bridge);
513 0 ▶ $result_class_names_and_ids{$result_class} ||= [];
Condition0%0/2
$result_class_names_and_ids{$result_class} ||= []
l!l
00
MC/DC0%0/1
$result_class_names_and_ids{$result_class} ||= []
$result_class_names_and_ids{$result_class}
Truth table0%0/2
A
A= $result_class_names_and_ids{$result_class}
Aresult
11
00
514  
515 0 my $id = $linking_id_value_for_bridge->($bridge);
516 0 push @{ $result_class_names_and_ids{ $result_class } }, $id;
517 }
518  
519 0 my @results;
520 0 foreach my $result_class ( keys %result_class_names_and_ids ) {
521 0 ▶ if($result_class->isa('UR::Value')) { #can't group queries together for UR::Values
Branch: 1 branch
BranchTrueFalseTotal
if ($result_class->isa('UR::Value')) { } 0 0 0
522 0 push @results, map { $result_class->get($result_filtering_property => $_, @_) } @{$result_class_names_and_ids{$result_class}};
523 } else {
524 0 push @results, $result_class->get($result_filtering_property => $result_class_names_and_ids{$result_class}, @_);
525 }
526 }
527  
528 0 ▶ if ($bridge_meta_params->{'-order'} || $bridge_meta_params->{'-order_by'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bridge_meta_params->{"-order"} or $bridge_meta_params->{"-order_by"}) 0 0 0
Condition0%0/3
$bridge_meta_params->{"-order"} or $bridge_meta_params->{"-order_by"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$bridge_meta_params->{"-order"} or $bridge_meta_params->{"-order_by"}
$bridge_meta_params->{"-order"} $bridge_meta_params->{"-order_by"}
Truth table0%0/3
A or B
A= $bridge_meta_params->{"-order"}B= $bridge_meta_params->{"-order_by"}
ABresult
1X1
011
000
529 my $results_sorter = _make_results_sorter_for_doubly_delegated_bridge_crosser(
530 $bridges,
531 0 ▶ sub { return $linking_id_value_for_bridge->($_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
532 0 ▶ sub { $_->id } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
533 0 @results = $results_sorter->(\@results);
534 }
535  
536 0 ▶ @results = map { $_->$final_result_property_name } @results if ($to_property_meta->via);
Branch: 1 branch
BranchTrueFalseTotal
if $to_property_meta->via 0 0 0
537 0 return @results;
538 0 };
539 }
540  
541 0 return;
542 }
543  
544 0 ▶sub _is_assignment_value {
Subroutine _is_assignment_value: not called CC=4 SCAR=30.0
545 return (
546 0 ▶ @_ == 1
Condition0%0/9
@_ == 1 && !(ref $_[0] && builtin::blessed($_[0]) && $_[0]->isa('UR::BoolExpr'))
!ll&&!rl&&r
000
ref $_[0] && builtin::blessed($_[0]) && $_[0]->isa('UR::BoolExpr')
!ll&&!rl&&r
000
ref $_[0] and builtin::blessed($_[0])
!ll&&!rl&&r
000
MC/DC0%0/4
@_ == 1 && !(ref $_[0] && builtin::blessed($_[0]) && $_[0]->isa('UR::BoolExpr'))
@_ == 1 ref $_[0] builtin::blessed($_[0]) $_[0]->isa('UR::BoolExpr')
Truth table0%0/5
A && not(B and C && D)
A= @_ == 1B= ref $_[0]C= builtin::blessed($_[0])D= $_[0]->isa('UR::BoolExpr')
ABCDresult
0XXX0
11110
10XX1
110X1
11101
547 and not (ref($_[0]) and Scalar::Util::blessed($_[0]) and $_[0]->isa("UR::BoolExpr"))
548 );
549 }
550  
551 10108 ▶sub mk_indirect_ro_accessor {
Subroutine mk_indirect_ro_accessor: called CC=3 SCAR=20.2
Pod undocumented
552 10108 my ($ur_object_type, $class_name, $accessor_name, $via, $to, $where) = @_;
553 10108 ▶ my @where = ($where ? @$where : ());
Branch: 1 branch
BranchTrueFalseTotal
$where ? : 1064 9044 10108
554 10108 my $full_name = join( '::', $class_name, $accessor_name );
555 10108 my $filterable_accessor_name = 'get_' . $accessor_name; # FIXME we need a better name for
556 10108 my $filterable_full_name = join( '::', $class_name, $filterable_accessor_name );
557  
558 # This is part of an experimental refactoring of indirect accessors. The goal is to
559 # get rid of all the special cases inside of _resolve_bridge_logic_for_indirect_property()
560 # and do the right thing with the Join data
561 10108 my (@collectors, @crossers);
562 0 ▶ my $accessor2 = Sub::Name::subname $full_name.'_new' => sub {
Subroutine __ANON__: not called CC=12 SCAR=50.5
563 0 my $self = shift;
564 0 ▶ Carp::croak("Assignment value passed to read-only indirect accessor $accessor_name for class $class_name") if @_ and _is_assignment_value(@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ and _is_assignment_value(@_) 0 0 0
Condition0%0/3
@_ and _is_assignment_value(@_)
!ll&&!rl&&r
000
MC/DC0%0/2
@_ and _is_assignment_value(@_)
@_ _is_assignment_value(@_)
Truth table0%0/3
A and B
A= @_B= _is_assignment_value(@_)
ABresult
0X0
100
111
565  
566 0 ▶ if ($class_name =~ m/^UR::/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class_name =~ /^UR::/) 0 0 0
567 # Some methods will recurse into here if called on a UR::* class (especially
568 # UR::BoolExpr), so do the dumb but safe thing
569 0 ▶ my $bridge_collector = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
570 0 my $self = shift;
571 0 my @results = $self->$via(@$where);
572 # Indirect has one properties must return a single undef value for an empty result, even in list context.
573 0 ▶ return if @results == 1 and not defined $results[0];
Branch: 1 branch
BranchTrueFalseTotal
if @results == 1 and not defined $results[0] 0 0 0
Condition0%0/3
@results == 1 and not defined $results[0]
!ll&&!rl&&r
000
MC/DC0%0/2
@results == 1 and not defined $results[0]
@results == 1 not defined $results[0]
Truth table0%0/3
A and not(B)
A= @results == 1B= not defined $results[0]
ABresult
0X0
100
111
574 0 return @results;
575 0 };
576  
577 #TODO: move this crosser closure logic down and get rid of the closure
578 0 my @filter = @_;
579 0 ▶ my $bridge_crosser = sub { return map { $_->$to(@filter) } @_ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
580 0 my @bridges = $bridge_collector->($self);
581 0 ▶ return unless @bridges;
Branch: 1 branch
BranchTrueFalseTotal
unless @bridges 0 0 0
582 0 ▶ return $self->context_return(@bridges) if ($to eq '-filter');
Branch: 1 branch
BranchTrueFalseTotal
if $to eq "-filter" 0 0 0
583  
584 0 my @results = $bridge_crosser->(@bridges);
585 0 return $self->context_return(@results);
586 }
587  
588 0 ▶ unless (@collectors) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@collectors) 0 0 0
589 0 require List::MoreUtils;
590  
591 0 my $prop_meta = $class_name->__meta__->property_meta_for_name($accessor_name);
592 0 my @join_list = $prop_meta->_resolve_join_chain();
593 0 foreach my $join ( @join_list ) {
594 0 my @source_property_names = @{$join->{source_property_names}};
595 0 ▶ my $collector = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
596 0 ▶ my @list = grep { defined && length } map { my $o = $_; map { $o->$_ } @source_property_names} @_;
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
597 0 ▶ return @list == 1 ? $list[0] : \@list;
Branch: 1 branch
BranchTrueFalseTotal
@list == 1 ? : 0 0 0
598 0 };
599 0 push @collectors, $collector;
600  
601 0 my $foreign_class = $join->{foreign_class};
602 0 my $crosser;
603 0 ▶ if (! $foreign_class->isa('UR::Value')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($foreign_class->isa("UR::Value")) 0 0 0
604 0 my @foreign_property_names = @{$join->{foreign_property_names}};
605  
606 0 ▶ $crosser = sub { my @get_params = List::MoreUtils::pairwise
Subroutine __ANON__: not called CC=1 SCAR=6.9
607 0 ▶ { $a => $b } @foreign_property_names, @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
608 0 return $foreign_class->get(@get_params); };
609 }
610 0 push @crossers, $crosser;
611 }
612 }
613  
614 0 my @working = ($self);
615  
616 # This can probably be rewritten with List::Util::reduce
617 0 ▶ for (my $i = 0; $i < @collectors; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @collectors) 0 0 0
618 0 ▶ last unless @working;
Branch: 1 branch
BranchTrueFalseTotal
unless @working 0 0 0
619 0 my @working = $collectors[$i]->(@working);
620 0 ▶ next unless $crossers[$i];
Branch: 1 branch
BranchTrueFalseTotal
unless $crossers[$i] 0 0 0
621 0 @working = $crossers[$i]->(@working);
622 }
623 0 $self->context_return(@working);
624 10108 };
625 #Sub::Install::reinstall_sub({
626 # into => $class_name,
627 # as => $accessor_name.'_new',
628 # code => $accessor2,
629 #});
630  
631  
632 10108 my($bridge_collector, $bridge_crosser);
633  
634 612 ▶ my $accessor = Sub::Name::subname $full_name => sub {
Subroutine direct_id_property_names: called CC=6 SCAR=19.4
635 612 my $self = shift;
636 612 ▶ Carp::croak("Assignment value passed to read-only indirect accessor $accessor_name for class $class_name") if @_ == 1 and _is_assignment_value(@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 and _is_assignment_value(@_) 0 612 612
Condition33%1/3
@_ == 1 and _is_assignment_value(@_)
!ll&&!rl&&r
61200
MC/DC0%0/2
@_ == 1 and _is_assignment_value(@_)
@_ == 1 _is_assignment_value(@_)
Truth table33%1/3
A and B
A= @_ == 1B= _is_assignment_value(@_)
ABresult
0X0
100
111
637  
638 612 ▶ unless ($bridge_collector) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($bridge_collector) 612 0 612
639 612 ($bridge_collector, $bridge_crosser)
640 = $ur_object_type->_resolve_bridge_logic_for_indirect_property($class_name, $accessor_name, $via, $to, \@where);
641 }
642  
643 612 my @bridges = $bridge_collector->($self);
644  
645 612 ▶ return unless @bridges;
Branch: 1 branch
BranchTrueFalseTotal
unless @bridges 0 612 612
646 612 ▶ return $self->context_return(@bridges) if ($to eq '-filter');
Branch: 1 branch
BranchTrueFalseTotal
if $to eq "-filter" 0 612 612
647  
648 612 my @results = $bridge_crosser->(\@bridges, @_);
649 612 $self->context_return(@results);
650 10108 };
651  
652 10108 ▶ unless ($accessor_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($accessor_name) 0 10108 10108
653 0 Carp::croak("No accessor name specified for read-only indirect accessor $accessor_name for class $class_name");
654 }
655  
656 Sub::Install::reinstall_sub({
657 10108 into => $class_name,
658 as => $accessor_name,
659 code => $accessor,
660 });
661  
662 10108 my $r_class_name;
663 0 ▶ my $r_class_name_resolver = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
664 0 ▶ return $r_class_name if $r_class_name;
Branch: 1 branch
BranchTrueFalseTotal
if $r_class_name 0 0 0
665  
666 0 my $linking_property = UR::Object::Property->get(class_name => $class_name, property_name => $via);
667 0 ▶ unless ($linking_property->data_type) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($linking_property->data_type) 0 0 0
668 0 Carp::croak "Property ${class_name}::${accessor_name}: via refers to a property with no data_type. Can't process filter";
669 }
670 0 my $final_property = UR::Object::Property->get(class_name => $linking_property->data_type,
671 property_name => $to);
672 0 ▶ unless ($final_property->data_type) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($final_property->data_type) 0 0 0
673 0 Carp::croak "Property ${class_name}::${accessor_name}: to refers to a property with no data_type. Can't process filter";
674 }
675 0 $r_class_name = $final_property->data_type;
676 10108 };
677  
678 0 ▶ my $filterable_accessor = Sub::Name::subname $filterable_full_name => sub {
Subroutine get_num_values: not called CC=6 SCAR=37.4
679 0 my $self = shift;
680 0 my @results = $self->$accessor_name();
681 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
682 0 my $rule;
683 0 ▶ if (@_ == 1 and ref($_[0]) and $_[0]->isa('UR::BoolExpr')) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] and $_[0]->isa('UR::BoolExpr')) { } 0 0 0
Condition0%0/6
@_ == 1 and ref $_[0] and $_[0]->isa("UR::BoolExpr")
!ll&&!rl&&r
000
@_ == 1 and ref $_[0]
!ll&&!rl&&r
000
MC/DC0%0/3
@_ == 1 and ref $_[0] and $_[0]->isa("UR::BoolExpr")
@_ == 1 ref $_[0] $_[0]->isa("UR::BoolExpr")
Truth table0%0/4
A and B and C
A= @_ == 1B= ref $_[0]C= $_[0]->isa("UR::BoolExpr")
ABCresult
0XX0
10X0
1100
1111
684 0 $rule = shift;
685 } else {
686 0 ▶ $r_class_name ||= $r_class_name_resolver->();
Condition0%0/3
$r_class_name ||= &$r_class_name_resolver()
l!l&&r!l&&!r
000
MC/DC0%0/2
$r_class_name ||= &$r_class_name_resolver()
$r_class_name &$r_class_name_resolver()
Truth table0%0/3
A ||= B
A= $r_class_nameB= &$r_class_name_resolver()
ABresult
1X1
011
000
687 0 $rule = UR::BoolExpr->resolve_normalized($r_class_name, @_);
688 }
689 0 @results = grep { $rule->evaluate($_) } @results;
690 }
691 0 $self->context_return(@results);
692 10108 };
693 10108 Sub::Install::reinstall_sub({
694 into => $class_name,
695 as => $filterable_accessor_name,
696 code => $filterable_accessor,
697 });
698  
699 }
700  
701  
702 0 ▶sub mk_indirect_rw_accessor {
Subroutine mk_indirect_rw_accessor: not called CC=6 SCAR=37.4
Pod undocumented
703 0 my ($ur_object_type, $class_name, $accessor_name, $via, $to, $where, $singular_name, $property_name) = @_;
704 0 ▶ $property_name ||= $accessor_name;
Condition0%0/3
$property_name ||= $accessor_name
l!l&&r!l&&!r
000
MC/DC0%0/2
$property_name ||= $accessor_name
$property_name $accessor_name
Truth table0%0/3
A ||= B
A= $property_nameB= $accessor_name
ABresult
1X1
011
000
705 0 ▶ my @where = ($where ? @$where : ());
Branch: 1 branch
BranchTrueFalseTotal
$where ? : 0 0 0
706 0 my $full_name = join( '::', $class_name, $accessor_name );
707  
708 0 my $update_strategy; # defined the first time we "set" a value through this
709 my $adder;
710 0 my $via_property_meta;
711 0 my $r_class_name;
712 0 my $is_many;
713  
714 0 ▶ my $resolve_update_strategy = sub {
Subroutine __ANON__: not called CC=9 SCAR=45.0
715 0 ▶ unless (defined $update_strategy) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $update_strategy) 0 0 0
716 # Resolve the strategy. We need to figure out if $to
717 # refers to an id-property. This is only called once, when the
718 # accessor is first used.
719  
720 # If we reference a remote object, and go to one of its id properties
721 # we must do a delete/create instead of property change. Note that
722 # this is only allowed when the remote object has no direct properties
723 # which are not id properties.
724  
725 0 my $my_property_meta = $class_name->__meta__->property_meta_for_name($property_name);
726 0 ▶ unless ($my_property_meta) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($my_property_meta) 0 0 0
727 0 Carp::croak("Failed to find property meta for '$property_name' on class $class_name");
728 }
729 0 $is_many = $my_property_meta->is_many;
730  
731 0 ▶ $via_property_meta ||= $class_name->__meta__->property_meta_for_name($via);
Condition0%0/3
$via_property_meta ||= $class_name->__meta__->property_meta_for_name($via)
l!l&&r!l&&!r
000
MC/DC0%0/2
$via_property_meta ||= $class_name->__meta__->property_meta_for_name($via)
$via_property_meta $class_name->__meta__->property_meta_for_name($via)
Truth table0%0/3
A ||= B
A= $via_property_metaB= $class_name->__meta__->property_meta_for_name($via)
ABresult
1X1
011
000
732 0 ▶ unless ($via_property_meta) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($via_property_meta) 0 0 0
733 0 Carp::croak("Failed to find property metadata for via property '$via' while resolving property '$property_name' on class $class_name");
734 }
735  
736 0 ▶ $r_class_name ||= $via_property_meta->data_type;
Condition0%0/3
$r_class_name ||= $via_property_meta->data_type
l!l&&r!l&&!r
000
MC/DC0%0/2
$r_class_name ||= $via_property_meta->data_type
$r_class_name $via_property_meta->data_type
Truth table0%0/3
A ||= B
A= $r_class_nameB= $via_property_meta->data_type
ABresult
1X1
011
000
737 0 ▶ unless ($r_class_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r_class_name) 0 0 0
738 0 Carp::croak("Cannot resolve property '$property_name' on class $class_name: It is via property '$via' which has no data_type");
739 }
740 0 my $r_class_meta = $r_class_name->__meta__;
741 0 ▶ unless ($r_class_meta) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r_class_meta) 0 0 0
742 0 Carp::croak("Cannot resolve property '$property_name' on class $class_name: It is via property '$via' with data_type $r_class_name which is not a valid class name");
743 }
744  
745 0 $adder = "add_" . $via_property_meta->singular_name;
746  
747 0 ▶ if ($my_property_meta->_involves_id_property) {
Branch: 1 branch
BranchTrueFalseTotal
if ($my_property_meta->_involves_id_property) { } 0 0 0
748 0 $update_strategy = 'delete-create'
749 }
750 else {
751 0 $update_strategy = 'change';
752 }
753 }
754 0 return $update_strategy;
755 0 };
756  
757 0 my ($bridge_collector, $bridge_crosser);
758 0 ▶ my $accessor = Sub::Name::subname $full_name => sub {
Subroutine __ANON__: not called CC=18 SCAR=58.3
759 0 my $self = shift;
760  
761 0 ▶ unless ($bridge_collector) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($bridge_collector) 0 0 0
762 0 ($bridge_collector, $bridge_crosser)
763 = $ur_object_type->_resolve_bridge_logic_for_indirect_property($class_name, $accessor_name, $via, $to, \@where);
764 }
765  
766 0 my @bridges = $bridge_collector->($self);
767  
768 0 ▶ if ( @_ == 1 and _is_assignment_value(@_) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and _is_assignment_value(@_)) 0 0 0
Condition0%0/3
@_ == 1 and _is_assignment_value(@_)
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and _is_assignment_value(@_)
@_ == 1 _is_assignment_value(@_)
Truth table0%0/3
A and B
A= @_ == 1B= _is_assignment_value(@_)
ABresult
0X0
100
111
769 0 ▶ $resolve_update_strategy->() unless (defined $update_strategy);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $update_strategy 0 0 0
770  
771 0 ▶ if ($update_strategy eq 'change') {
Branch: 2 branches
BranchTrueFalseTotal
if ($update_strategy eq 'change') { } 0 0 0
elsif ($update_strategy eq 'delete-create') { } 0 0 0
772 0 ▶ if (@bridges == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (@bridges == 0) { } 0 0 0
elsif (@bridges > 1) { } 0 0 0
773 #print "adding via $adder @where :::> $to @_\n";
774 0 my $exception = do {
775 0 local $@;
776 0 @bridges = eval { $self->$adder(@where, $to => $_[0]) };
777 0 $@;
778 };
779 0 ▶ if ($exception) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exception) 0 0 0
780 0 my $r_class_meta = $r_class_name->__meta__;
781 0 my $property_meta = $r_class_meta->property($to);
782 0 ▶ if ($property_meta) {
Branch: 1 branch
BranchTrueFalseTotal
if ($property_meta) { } 0 0 0
783 # Re-throw the original exception
784 0 die $exception;
785 } else {
786 0 Carp::croak("Couldn't create a new object through indirect property "
787 . "'$accessor_name' on $class_name. 'to' is $to which is not a property on $r_class_name.");
788 }
789 }
790 #WAS > Carp::confess("Cannot set $accessor_name on $class_name $self->{id}: property is via $via which is not set!");
791 }
792 elsif (@bridges > 1) {
793 0 Carp::croak("Cannot set '$accessor_name' on $class_name id '$self->{id}': multiple instances of '$via' found, via which the property is set");
794 }
795 #print "updating $bridges[0] $to to @_\n";
796 0 return $bridges[0]->$to(@_);
797 }
798 elsif ($update_strategy eq 'delete-create') {
799 0 ▶ if (@bridges > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@bridges > 1) { } 0 0 0
800 0 Carp::croak("Cannot set '$accessor_name' on $class_name $self->{id}: multiple instances of '$via' found, via which the property is set");
801 }
802 else {
803 0 ▶ if (@bridges) {
Branch: 1 branch
BranchTrueFalseTotal
if (@bridges) 0 0 0
804 #print "deleting $bridges[0]\n";
805 0 $bridges[0]->delete;
806 }
807 #print "adding via $adder @where :::> $to @_\n";
808 0 @bridges = $self->$adder(@where, $to => $_[0]);
809 0 ▶ unless (@bridges) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@bridges) 0 0 0
810 0 Carp::croak("Failed to add bridge for '$accessor_name' on $class_name if '$self->{id}': method $adder returned false");
811 }
812 }
813 }
814 }
815 0 ▶ if (not defined $is_many) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $is_many) 0 0 0
816 0 $resolve_update_strategy->();
817 }
818  
819 0 ▶ if ($is_many) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_many) { } 0 0 0
820 0 ▶ return unless @bridges;
Branch: 1 branch
BranchTrueFalseTotal
unless @bridges 0 0 0
821 0 my @results = $bridge_crosser->(\@bridges, @_);
822 0 $self->context_return(@results);
823 } else {
824 0 ▶ return undef unless @bridges;
Branch: 1 branch
BranchTrueFalseTotal
unless @bridges 0 0 0
825 0 my @results = map { $_->$to(@_) } @bridges;
826 0 $self->context_return(@results);
827 }
828 0 };
829  
830 0 Sub::Install::reinstall_sub({
831 into => $class_name,
832 as => $accessor_name,
833 code => $accessor,
834 });
835  
836 0 ▶ if ($singular_name) { # True if we're defining an is_many indirect property
Branch: 1 branch
BranchTrueFalseTotal
if ($singular_name) 0 0 0
837 # Add
838 0 my $via_adder;
839 0 my $adder_method_name = 'add_' . $singular_name;
840 0 ▶ if ($class_name->can($adder_method_name)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class_name->can($adder_method_name)) 0 0 0
841 0 $adder_method_name = '__' . $adder_method_name;
842 }
843 0 ▶ my $adder_method = Sub::Name::subname $class_name . '::' . $adder_method_name => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
844 0 my($self) = shift;
845  
846  
847 0 ▶ $resolve_update_strategy->() unless (defined $update_strategy);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $update_strategy 0 0 0
848 0 ▶ unless (defined $via_adder) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $via_adder) 0 0 0
849 0 $via_adder = "add_" . $via_property_meta->singular_name;
850 }
851  
852 # By default, a single value will come in which is the remote value
853 # we just add the appropriate property name to it. If multiple
854 # values come in we trust the caller to be giving additional params.
855 0 ▶ if (@_ == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) 0 0 0
856 0 unshift @_, $to;
857 }
858 0 $self->$via_adder(@where,@_);
859 0 };
860 0 Sub::Install::reinstall_sub({
861 into => $class_name,
862 as => $adder_method_name,
863 code => $adder_method,
864 });
865  
866 # Remove
867 0 my $via_remover;
868 0 my $remover_method_name = 'remove_' . $singular_name;
869 0 ▶ if ($class_name->can($remover_method_name)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class_name->can($remover_method_name)) 0 0 0
870 0 $remover_method_name = '__' . $remover_method_name;
871 }
872 0 ▶ my $remover_method = Sub::Name::subname $class_name . '::' . $remover_method_name => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
873 0 my($self) = shift;
874  
875 0 ▶ $resolve_update_strategy->() unless (defined $update_strategy);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $update_strategy 0 0 0
876 0 ▶ unless (defined $via_remover) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $via_remover) 0 0 0
877 0 $via_remover = "remove_" . $via_property_meta->singular_name;
878 }
879  
880 # By default, a single value will come in which is the remote value
881 # we just remove the appropriate property name to it. If multiple
882 # values come in we trust the caller to be giving removeitional params.
883 0 ▶ if (@_ == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) 0 0 0
884 0 unshift @_, $to;
885 }
886 0 $self->$via_remover(@where,@_);
887 0 };
888 0 Sub::Install::reinstall_sub({
889 into => $class_name,
890 as => $remover_method_name,
891 code => $remover_method,
892 });
893 }
894  
895 }
896  
897  
898 798 ▶sub mk_calculation_accessor {
Subroutine mk_calculation_accessor: called CC=15 SCAR=44.3
Pod undocumented
899 798 my ($self, $class_name, $accessor_name, $calculation_src, $calculate_from, $params, $is_cached, $column_name) = @_;
900  
901 798 my $accessor;
902 my @src;
903  
904 798 ▶ if (not defined $calculation_src or $calculation_src eq '') {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $calculation_src or $calculation_src eq '') { } 0 798 798
elsif (ref $calculation_src eq 'CODE') { } 0 798 798
elsif ($calculation_src =~ /^[^\:\W]+$/) { } 0 798 798
Condition33%1/3
not defined $calculation_src or $calculation_src eq ""
l!l&&r!l&&!r
00798
MC/DC0%0/2
not defined $calculation_src or $calculation_src eq ""
not defined $calculation_src $calculation_src eq ""
Truth table33%1/3
not(A) or B
A= not defined $calculation_srcB= $calculation_src eq ""
ABresult
1X1
011
000
905 0 $accessor = \&{ $class_name . '::' . $accessor_name };
906 0 ▶ unless ($accessor) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($accessor) 0 0 0
907 0 Carp::croak "$accessor_name not defined in $class_name! Define it, or specify a calculate => sub{} or calculate => \$perl_src in the class definition.";
908 }
909 }
910 elsif (ref($calculation_src) eq 'CODE') {
911 0 ▶ $accessor = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
912 0 my $self = shift;
913 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
914 0 Carp::croak("$class_name $accessor_name is a read-only property derived from @$calculate_from");
915 }
916 0 return $calculation_src->(map { $self->$_ } @$calculate_from);
917 0 };
918 }
919 elsif ($calculation_src =~ /^[^\:\W]+$/) {
920 # built-in formula like 'sum' or 'product'
921 0 my $module_name = "UR::Object::Type::AccessorWriter::" . ucfirst(lc($calculation_src));
922 0 my $exception = do {
923 0 local $@;
924 0 eval "use $module_name";
925 0 $@;
926 };
927 0 ▶ die $exception if $exception;
Branch: 1 branch
BranchTrueFalseTotal
if $exception 0 0 0
928 @src = (
929 "sub ${class_name}::${accessor_name} {",
930 'my $self = $_[0];',
931 0 "${module_name}->calculate(\$self, [" . join(",", map { "'$_'" } @$calculate_from) . "], \@_)",
932 '}'
933 );
934 }
935 else {
936 @src = (
937 "sub ${class_name}::${accessor_name} {",
938 ($params ? 'my ($self,%params) = @_;' : 'my $self = $_[0];'),
939 0 ▶ (map { "my \$$_ = \$self->$_;" } @$calculate_from),
Branch: 1 branch
BranchTrueFalseTotal
$params ? : 0 798 798
940 0 ▶ ($params ? (map { "my \$$_ = delete \$params{'$_'};" } @$params) : ()),
Branch: 1 branch
BranchTrueFalseTotal
$params ? : 0 798 798
941 $calculation_src,
942 '}'
943 );
944 }
945  
946 798 ▶ if (!$accessor) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($accessor) 798 0 798
947 798 ▶ if (@src) {
Branch: 1 branch
BranchTrueFalseTotal
if (@src) { } 798 0 798
948 798 my $src = join("\n",@src);
949 #print ">>$src<<\n";
950 798 my $exception = do {
951 798 local $@;
952 0 ▶ eval $src;
Subroutine all_class_metas: not called CC=1 SCAR=5.1
Subroutine id_properties: not called CC=1 SCAR=5.1
Subroutine properties: not called CC=1 SCAR=5.1
953 798 $@;
954 };
955 798 ▶ if ($exception) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exception) 0 798 798
956 0 Carp::croak "ERROR IN CALCULATED PROPERTY SOURCE: $class_name $accessor_name\n$exception\n";
957 }
958 798 $accessor = \&{ $class_name . '::' . $accessor_name };
959 798 ▶ unless ($accessor) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($accessor) 0 798 798
960 0 Carp::confess("Failed to generate code body for calculated property ${class_name}::${accessor_name}!");
961 }
962 }
963 else {
964 0 Carp::croak "Error implementing calcuation accessor for $class_name $accessor_name!";
965 }
966 }
967  
968 798 ▶ if ($accessor and $is_cached) {
Branch: 1 branch
BranchTrueFalseTotal
if ($accessor and $is_cached) 0 798 798
Condition33%1/3
$accessor and $is_cached
!ll&&!rl&&r
07980
MC/DC0%0/2
$accessor and $is_cached
$accessor $is_cached
Truth table33%1/3
A and B
A= $accessorB= $is_cached
ABresult
0X0
100
111
969 # Wrap the already-compiled accessor in another function to memoize the
970 # result and save the data into the object
971 0 my $calculator_sub = $accessor;
972 0 ▶ $accessor = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
973 0 ▶ if (@_ > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 0 0 0
974 0 Carp::croak("Cannot change property $accessor_name for class $class_name: cached calculated properties are read-only");
975 }
976 0 ▶ unless (exists $_[0]->{$accessor_name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $_[0]{$accessor_name}) 0 0 0
977 0 $_[0]->{$accessor_name} = $calculator_sub->(@_);
978 }
979 0 return $_[0]->{$accessor_name};
980 0 };
981  
982 # Make a method to clear the cached value and force another calculation
983 0 my $invalidator_name;
984 0 ($invalidator_name = $accessor_name) =~ s/^_+//;
985 0 $invalidator_name = "__invalidate_${invalidator_name}__";
986 Sub::Install::reinstall_sub({
987 into => $class_name,
988 as => $invalidator_name,
989 0 ▶ code => sub { delete $_[0]->{$accessor_name} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
990 0 });
991 }
992  
993 798 my $full_name = join( '::', $class_name, $accessor_name );
994 798 $accessor = Sub::Name::subname $full_name => $accessor;
995 798 Sub::Install::reinstall_sub({
996 into => $class_name,
997 as => $accessor_name,
998 code => $accessor,
999 });
1000  
1001 798 return $accessor;
1002 }
1003  
1004 0 ▶sub mk_dimension_delegate_accessors {
Subroutine mk_dimension_delegate_accessors: not called CC=1 SCAR=5.7
Pod undocumented
1005 0 my ($self, $accessor_name, $ref_class_name, $non_id_properties, $other_accessor_name, $is_transient) = @_;
1006  
1007 # Like mk_rw_accessor, but knows that this accessor is a foreign
1008 # key to a dimension table, and configures additional accessors.
1009 # Also makes this accessor "smart", to resolve the dimension
1010 # id only when needed.
1011  
1012 # Make EAV-like accessors for all of the remote properties
1013 0 my $class_name = $self->class_name;
1014  
1015 0 my $full_name = join( '::', $class_name, $other_accessor_name );
1016 0 ▶ my $other_accessor = Sub::Name::subname $full_name => sub {
Subroutine __ANON__: not called CC=12 SCAR=47.8
1017 0 my $self = shift;
1018 0 my $delegate_id = $self->{$accessor_name};
1019 0 ▶ if (defined($delegate_id)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $delegate_id) { } 0 0 0
1020 # We're currently delegating.
1021 0 my $delegate = $ref_class_name->get($delegate_id);
1022 0 ▶ if (not @_) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @_) { } 0 0 0
1023 # A simple get. Delegate.
1024 0 return $delegate->$other_accessor_name(@_);
1025 }
1026 else {
1027 # We're setting a value.
1028 # Switch from delegating to local access.
1029 # We'll switch back next-time the dimension ID
1030 # is actually requested by its accessor
1031 # (farther below).
1032 0 my $old = $delegate->$other_accessor_name;
1033 0 my $new = shift;
1034 0 my $different;
1035 0 my $exception = do {
1036 0 local $@;
1037 0 ▶ $different = eval { no warnings; $old ne $new };
Subroutine BEGIN: called CC=1 SCAR=0.6
1038 0 $@;
1039 };
1040 0 ▶ if ($different or $exception =~ m/has no overloaded magic/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($different or $exception =~ /has no overloaded magic/) 0 0 0
Condition0%0/3
$different or $exception =~ /has no overloaded magic/
l!l&&r!l&&!r
000
MC/DC0%0/2
$different or $exception =~ /has no overloaded magic/
$different $exception =~ /has no overloaded magic/
Truth table0%0/3
A or B
A= $differentB= $exception =~ /has no overloaded magic/
ABresult
1X1
011
000
1041 0 $self->{$accessor_name} = undef;
1042 0 for my $property (@$non_id_properties) {
1043 0 ▶ if ($property eq $other_accessor_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($property eq $other_accessor_name) { } 0 0 0
1044 # set the value locally
1045 0 $self->{$property} = $new;
1046 }
1047 else {
1048 # grab the data from the (now previous) delegate
1049 0 $self->{$property} = $delegate->$property;
1050 }
1051 }
1052 0 ▶ $self->__signal_change__( $other_accessor_name, $old, $new ) unless $is_transient;
Branch: 1 branch
BranchTrueFalseTotal
unless $is_transient 0 0 0
1053 0 return $new;
1054 }
1055 }
1056 }
1057 else {
1058 # We are not currently delegating.
1059 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
1060 # set
1061 0 my $old = $self->{ $other_accessor_name };
1062 0 my $new = shift;
1063 0 my $different;
1064 0 my $exception = do {
1065 0 local $@;
1066 0 ▶ $different = eval { no warnings; $old ne $new };
Subroutine BEGIN: called CC=1 SCAR=0.6
1067 0 $@;
1068 };
1069 0 ▶ if ($different or $exception =~ m/has no overloaded magic/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($different or $exception =~ /has no overloaded magic/) 0 0 0
Condition0%0/3
$different or $exception =~ /has no overloaded magic/
l!l&&r!l&&!r
000
MC/DC0%0/2
$different or $exception =~ /has no overloaded magic/
$different $exception =~ /has no overloaded magic/
Truth table0%0/3
A or B
A= $differentB= $exception =~ /has no overloaded magic/
ABresult
1X1
011
000
1070 0 $self->{ $other_accessor_name } = $new;
1071 0 ▶ $self->__signal_change__( $other_accessor_name, $old, $new ) unless $is_transient;
Branch: 1 branch
BranchTrueFalseTotal
unless $is_transient 0 0 0
1072 }
1073 0 return $new;
1074 }
1075 else {
1076 # get
1077 0 return $self->{ $other_accessor_name };
1078 }
1079 }
1080 0 };
1081  
1082 0 Sub::Install::reinstall_sub({
1083 into => $class_name,
1084 as => $other_accessor_name,
1085 code => $other_accessor,
1086 });
1087 }
1088  
1089 0 ▶sub mk_dimension_identifying_accessor {
Subroutine mk_dimension_identifying_accessor: not called CC=1 SCAR=5.9
Pod undocumented
1090 0 my ($self, $accessor_name, $ref_class_name, $non_id_properties, $is_transient) = @_;
1091  
1092 # Like mk_rw_accessor, but knows that this accessor is a foreign
1093 # key to a dimension table, and configures additional accessors.
1094 # Also makes this accessor "smart", to resolve the dimension
1095 # id only when needed.
1096  
1097 # Make EAV-like accessors for all of the remote properties
1098 0 my $class_name = $self->class_name;
1099  
1100 # Make the actual accessor for the id_by property
1101 0 my $full_name = join( '::', $class_name, $accessor_name );
1102 0 ▶ my $accessor = Sub::Name::subname $full_name => sub {
Subroutine __ANON__: not called CC=7 SCAR=38.1
1103 0 ▶ if (@_ > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 0 0 0
1104 0 my $old = $_[0]->{ $accessor_name };
1105 0 my $new = $_[1];
1106 0 my $different;
1107 0 my $exception = do {
1108 0 local $@;
1109 0 ▶ $different = eval { no warnings; $old ne $new };
Subroutine BEGIN: called CC=1 SCAR=0.6
1110 0 $@;
1111 };
1112 0 ▶ if ($different or $exception =~ m/has no overloaded magic/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($different or $exception =~ /has no overloaded magic/) 0 0 0
Condition0%0/3
$different or $exception =~ /has no overloaded magic/
l!l&&r!l&&!r
000
MC/DC0%0/2
$different or $exception =~ /has no overloaded magic/
$different $exception =~ /has no overloaded magic/
Truth table0%0/3
A or B
A= $differentB= $exception =~ /has no overloaded magic/
ABresult
1X1
011
000
1113 0 $_[0]->{ $accessor_name } = $new;
1114 0 ▶ $_[0]->__signal_change__( $accessor_name, $old, $new ) unless $is_transient;
Branch: 1 branch
BranchTrueFalseTotal
unless $is_transient 0 0 0
1115 }
1116 0 return $new;
1117 }
1118 0 ▶ if (not defined $_[0]->{ $accessor_name }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_[0]{$accessor_name}) 0 0 0
1119 # Resolve an ID for the current set of values
1120 # Switch to delegating to that object.
1121 0 my %params;
1122 0 my $self = $_[0];
1123 0 @params{@$non_id_properties} = delete @$self{@$non_id_properties};
1124 0 my $delegate = $ref_class_name->get_or_create(%params);
1125 0 ▶ return undef unless $delegate;
Branch: 1 branch
BranchTrueFalseTotal
unless $delegate 0 0 0
1126 0 $_[0]->{ $accessor_name } = $delegate->id;
1127 }
1128 0 return $_[0]->{ $accessor_name };
1129 0 };
1130  
1131 0 Sub::Install::reinstall_sub({
1132 into => $class_name,
1133 as => $accessor_name,
1134 code => $accessor,
1135 });
1136 }
1137  
1138 sub mk_rw_class_accessor
1139 0 ▶{
Subroutine mk_rw_class_accessor: not called CC=1 SCAR=5.6
Pod undocumented
1140 0 my ($self, $class_name, $accessor_name, $column_name, $is_transient, $variable_value, $calc_default) = @_;
1141  
1142 0 my $full_accessor_name = $class_name . "::" . $accessor_name;
1143 0 ▶ my $accessor = Sub::Name::subname $full_accessor_name => sub {
Subroutine __ANON__: not called CC=6 SCAR=34.5
1144 0 ▶ if (@_ > 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ > 1) { } 0 0 0
elsif (defined $calc_default) { } 0 0 0
1145 0 my $old = $variable_value;
1146 0 $variable_value = $_[1];
1147  
1148 0 my $different;
1149 0 my $exception = do {
1150 0 local $@;
1151 0 ▶ $different = eval { no warnings; $old ne $variable_value };
Subroutine BEGIN: called CC=1 SCAR=0.6
1152 0 $@;
1153 };
1154 0 ▶ if ($different or $exception =~ m/has no overloaded magic/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($different or $exception =~ /has no overloaded magic/) 0 0 0
Condition0%0/3
$different or $exception =~ /has no overloaded magic/
l!l&&r!l&&!r
000
MC/DC0%0/2
$different or $exception =~ /has no overloaded magic/
$different $exception =~ /has no overloaded magic/
Truth table0%0/3
A or B
A= $differentB= $exception =~ /has no overloaded magic/
ABresult
1X1
011
000
1155 0 ▶ $_[0]->__signal_change__( $accessor_name, $old, $variable_value ) unless $is_transient;
Branch: 1 branch
BranchTrueFalseTotal
unless $is_transient 0 0 0
1156 }
1157 } elsif (defined $calc_default) {
1158 0 $variable_value = $calc_default->();
1159 }
1160 0 undef $calc_default;
1161 0 return $variable_value;
1162 0 };
1163 0 Sub::Install::reinstall_sub({
1164 into => $class_name,
1165 as => $accessor_name,
1166 code => $accessor,
1167 });
1168  
1169 }
1170  
1171 0 ▶sub mk_ro_class_accessor {
Subroutine mk_ro_class_accessor: not called CC=1 SCAR=5.7
Pod undocumented
1172 0 my($self, $class_name, $accessor_name, $column_name, $variable_value, $calc_default) = @_;
1173  
1174 0 my $full_accessor_name = $class_name . "::" . $accessor_name;
1175 0 ▶ my $accessor = Sub::Name::subname $full_accessor_name => sub {
Subroutine __ANON__: not called CC=7 SCAR=37.6
1176 0 ▶ if (@_ > 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ > 1) { } 0 0 0
elsif (defined $calc_default) { } 0 0 0
1177 0 my $new = $_[1];
1178  
1179 0 my $different;
1180 0 my $exception = do{
1181 0 local $@;
1182 0 ▶ $different = eval { no warnings; $variable_value ne $new };
Subroutine BEGIN: called CC=1 SCAR=0.6
1183 0 $@;
1184 };
1185 0 ▶ if ($different or $exception =~ m/has no overloaded magic/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($different or $exception =~ /has no overloaded magic/) 0 0 0
Condition0%0/3
$different or $exception =~ /has no overloaded magic/
l!l&&r!l&&!r
000
MC/DC0%0/2
$different or $exception =~ /has no overloaded magic/
$different $exception =~ /has no overloaded magic/
Truth table0%0/3
A or B
A= $differentB= $exception =~ /has no overloaded magic/
ABresult
1X1
011
000
1186 0 ▶ $new = defined($new) ? $new : '(undef)';
Branch: 1 branch
BranchTrueFalseTotal
defined $new ? : 0 0 0
1187 0 ▶ my $report_variable_value = defined($variable_value) ? $variable_value : '(undef)';
Branch: 1 branch
BranchTrueFalseTotal
defined $variable_value ? : 0 0 0
1188 0 Carp::croak("Cannot change read-only class-wide property $accessor_name for class $class_name from $report_variable_value to $new!");
1189 }
1190 } elsif (defined $calc_default) {
1191 0 $variable_value = $calc_default->();
1192 }
1193 0 undef $calc_default;
1194 0 return $variable_value;
1195 0 };
1196 0 Sub::Install::reinstall_sub({
1197 into => $class_name,
1198 as => $accessor_name,
1199 code => $accessor,
1200 });
1201 }
1202  
1203  
1204  
1205  
1206 798 ▶sub mk_object_set_accessors {
Subroutine mk_object_set_accessors: called CC=10 SCAR=43.8
Pod undocumented
1207 798 my ($self, $class_name, $singular_name, $plural_name, $reverse_as, $r_class_name, $where) = @_;
1208  
1209 # These are set by the resolver closure below, and kept in scope by the other closures
1210 798 my $rule_template;
1211 my $r_class_meta;
1212 798 my @property_names;
1213 798 ▶ my @where = ($where ? @$where : ());
Branch: 1 branch
BranchTrueFalseTotal
$where ? : 532 266 798
1214  
1215 0 ▶ my $rule_resolver = sub {
Subroutine __ANON__: not called CC=24 SCAR=64.0
1216 0 my ($obj) = @_;
1217 0 my $loading_r_class_error = '';
1218 0 ▶ if (defined $r_class_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $r_class_name) 0 0 0
1219 0 my $exception = do {
1220 0 local $@;
1221 0 eval {
1222 0 $r_class_meta = UR::Object::Type->is_loaded($r_class_name);
1223 0 ▶ unless ($r_class_meta or __PACKAGE__->use_module_with_namespace_constraints($r_class_name)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r_class_meta or __PACKAGE__->use_module_with_namespace_constraints($r_class_name)) 0 0 0
Condition0%0/3
$r_class_meta or __PACKAGE__->use_module_with_namespace_constraints($r_class_name)
l!l&&r!l&&!r
000
MC/DC0%0/2
$r_class_meta or __PACKAGE__->use_module_with_namespace_constraints($r_class_name)
$r_class_meta __PACKAGE__->use_module_with_namespace_constraints($r_class_name)
Truth table0%0/3
A or B
A= $r_class_metaB= __PACKAGE__->use_module_with_namespace_constraints($r_class_name)
ABresult
1X1
011
000
1224 # Don't die yet. The named class may not have a file associated with it
1225 0 $loading_r_class_error = "Couldn't load class $r_class_name: $@";
1226 0 $@ = '';
1227 }
1228  
1229 0 ▶ unless ($r_class_meta) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r_class_meta) 0 0 0
1230 0 $r_class_name->class;
1231 0 $r_class_meta = UR::Object::Type->get(class_name => $r_class_name);
1232 }
1233 };
1234 0 $@;
1235 };
1236 0 ▶ if ($exception) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exception) 0 0 0
1237 0 $loading_r_class_error .= "Couldn't get class object for $r_class_name: $exception";
1238 }
1239 }
1240 0 ▶ if ($r_class_meta and not $reverse_as) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r_class_meta and not $reverse_as) 0 0 0
Condition0%0/3
$r_class_meta and not $reverse_as
!ll&&!rl&&r
000
MC/DC0%0/2
$r_class_meta and not $reverse_as
$r_class_meta not $reverse_as
Truth table0%0/3
A and not(B)
A= $r_class_metaB= not $reverse_as
ABresult
0X0
100
111
1241 # We have a real class on the other end, and it did not specify know to link back to us.
1242 # Try to infer how, otherwise fall back to the same logic we use with "primitives".
1243 0 my @possible_relationships = grep { $_->data_type eq $class_name }
1244 0 grep { defined $_->data_type }
1245 $r_class_meta->all_property_metas();
1246  
1247 0 ▶ if (@possible_relationships > 1) {
Branch: 3 branches
BranchTrueFalseTotal
if (@possible_relationships > 1) { } 0 0 0
elsif (@possible_relationships == 1) { } 0 0 0
elsif (@possible_relationships == 0) { } 0 0 0
1248 Carp::croak "$class_name has an ambiguous definition for property \"$singular_name\"."
1249 . " The target class $r_class_name has " . scalar(@possible_relationships)
1250 . " relationships which reference back to $class_name."
1251 . " Correct by adding \"reverse_as => X\" to ${class_name}'s \"$singular_name\" definition one of the following values: "
1252 0 . join(",",map { '"' . $_->delegation_name . '"' } @possible_relationships) . ".\n";
1253 }
1254 elsif (@possible_relationships == 1) {
1255 0 $reverse_as = $possible_relationships[0]->property_name;
1256 }
1257 elsif (@possible_relationships == 0) {
1258 # we now fall through to the logic below and try direct arrayref storage
1259 #die "No relationships found between $r_class_name and $class_name. Error in definition for $class_name $singular_name!"
1260 }
1261 }
1262 0 ▶ if ($reverse_as and ! $r_class_meta) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reverse_as and not $r_class_meta) 0 0 0
Condition0%0/3
$reverse_as and not $r_class_meta
!ll&&!rl&&r
000
MC/DC0%0/2
$reverse_as and not $r_class_meta
$reverse_as not $r_class_meta
Truth table0%0/3
A and not(B)
A= $reverse_asB= not $r_class_meta
ABresult
0X0
100
111
1263 # we've resolved reverse_as, but there's not r_class_meta?!
1264 0 $self->error_message("Can't resolve reverse relationship $class_name -> $plural_name. No class metadata for $r_class_name");
1265 0 ▶ if ($loading_r_class_error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($loading_r_class_error) { } 0 0 0
1266 0 Carp::croak "While loading $r_class_name: $loading_r_class_error";
1267 } else {
1268 0 Carp::croak "Is class $r_class_name defined anywhere?";
1269 }
1270 }
1271  
1272 0 ▶ if ($reverse_as) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reverse_as) { } 0 0 0
1273 # join to get the data...
1274 0 ▶ unless ($r_class_meta) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r_class_meta) 0 0 0
1275 0 Carp::croak("No remote class metadata found for class $r_class_name while resolving property '$singular_name' of class $class_name");
1276 }
1277 0 my $property_meta = $r_class_meta->property_meta_for_name($reverse_as);
1278 0 ▶ unless ($property_meta) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($property_meta) 0 0 0
1279 0 Carp::croak "Can't resolve reverse relationship $class_name -> $plural_name. Remote class $r_class_name has no property $reverse_as";
1280 }
1281 0 my @get_params;
1282 0 ▶ if ($property_meta->via) {
Branch: 1 branch
BranchTrueFalseTotal
if ($property_meta->via) { } 0 0 0
1283 # get_property_name_pairs_for_join() only works for properties connected directly.
1284 # we still need to use it during initialization, but for more complicated relationships
1285 # this should do the right thing
1286 0 push @get_params, $property_meta->property_name . '.id' => $obj->id;
1287 0 push @property_names, 'id';
1288 } else {
1289 0 my @property_links = $property_meta->get_property_name_pairs_for_join;
1290 0 for my $link (@property_links) {
1291 0 my $my_property_name = $link->[1];
1292 0 push @property_names, $my_property_name;
1293 0 ▶ unless ($obj->can($my_property_name)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($obj->can($my_property_name)) 0 0 0
1294 0 Carp::croak "Cannot handle indirect relationship $r_class_name -> $reverse_as. Class $class_name has no property named $my_property_name";
1295 }
1296 0 ▶ push @get_params, $link->[0], ($obj->$my_property_name || undef);
Condition0%0/2
$obj->$my_property_name || undef
l!l
00
MC/DC0%0/1
$obj->$my_property_name || undef
$obj->$my_property_name
Truth table0%0/2
A
A= $obj->$my_property_name
Aresult
11
00
1297 }
1298 }
1299  
1300 0 ▶ if (my $id_class_by = $property_meta->id_class_by) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $id_class_by = $property_meta->id_class_by) 0 0 0
1301 0 push @get_params, $id_class_by, $obj->class;
1302 0 push @property_names, 'class';
1303 }
1304 0 my $tmp_rule = $r_class_name->define_boolexpr(@get_params,@where);
1305 0 ▶ if (my $order_by = $property_meta->order_by) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $order_by = $property_meta->order_by) 0 0 0
1306 0 push @get_params, $order_by;
1307 }
1308 0 $rule_template = $tmp_rule->template;
1309 0 ▶ unless ($rule_template) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rule_template) 0 0 0
1310 0 Carp::croak "Error generating rule template to handle indirect relationship $class_name $singular_name referencing $r_class_name!";
1311 }
1312 0 return $tmp_rule;
1313 }
1314 else {
1315 # data is stored locally on the hashref
1316 #die "No relationships found between $r_class_name and $class_name. Error in definition for $class_name $singular_name!"
1317 }
1318 798 };
1319  
1320 798 my @where_values;
1321 798 ▶ for (my $i = 1; $i < @where; $i+=2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @where) 798 798 1596
1322 798 ▶ if (ref($where[$i]) eq 'HASH' and exists($where[$i]->{'operator'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $where[$i] eq 'HASH' and exists $where[$i]{'operator'}) { } 0 798 798
Condition33%1/3
ref $where[$i] eq "HASH" and exists $where[$i]{"operator"}
!ll&&!rl&&r
79800
MC/DC0%0/2
ref $where[$i] eq "HASH" and exists $where[$i]{"operator"}
ref $where[$i] eq "HASH" exists $where[$i]{"operator"}
Truth table33%1/3
A and B
A= ref $where[$i] eq "HASH"B= exists $where[$i]{"operator"}
ABresult
0X0
100
111
1323 0 push @where_values, $where[$i]->{'value'}; # the operator is already stored in the template
1324 } else {
1325 798 push @where_values, $where[$i];
1326 }
1327 }
1328  
1329 # These will behave specially if the rule does not specify the ID, or all of the ID.
1330 798 my @params_prefix;
1331 798 my $params_prefix_resolved = 0;
1332 0 ▶ my $params_prefix_resolver = sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
1333 # handle the case of has-many primitives
1334 0 ▶ return unless $r_class_meta;
Branch: 1 branch
BranchTrueFalseTotal
unless $r_class_meta 0 0 0
1335  
1336 0 my $r_ids = $r_class_meta->property_meta_for_name($reverse_as)->{id_by};
1337  
1338 0 my $cmeta = UR::Object::Type->get($class_name);
1339 0 ▶ my $pmeta = $plural_name ? $cmeta->{has}{$plural_name} : $cmeta->{has}{$singular_name};
Branch: 1 branch
BranchTrueFalseTotal
$plural_name ? : 0 0 0
1340 0 ▶ if (my $specify_by = $pmeta->{specify_by}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $specify_by = $pmeta->{'specify_by'}) { } 0 0 0
1341 0 @params_prefix = ($specify_by);
1342 }
1343 else {
1344 # TODO: should this really be an auto-setting of the specify_by meta property?
1345 0 my @id_property_names = $r_class_name->__meta__->id_property_names;
1346 @params_prefix =
1347 grep {
1348 0 my $id_property_name = $_;
1349 0 ▶ ( (grep { $id_property_name eq $_ } @$r_ids) ? 0 : 1)
Branch: 1 branch
BranchTrueFalseTotal
grep({$id_property_name eq $_;} @$r_ids) ? : 0 0 0
1350 }
1351 @id_property_names;
1352  
1353 # We only do the special single-value spec when there is one property not specified by the rule.
1354 # This is common for a multi-column primary key where all columns reference a parent object, except an index value, etc.
1355 0 ▶ @params_prefix = () unless scalar(@params_prefix) == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @params_prefix == 1 0 0 0
1356 }
1357 0 $params_prefix_resolved = 1;
1358 798 };
1359  
1360 798 ▶ if (!$plural_name || $singular_name ne $plural_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $plural_name or $singular_name ne $plural_name) 798 0 798
Condition33%1/3
not $plural_name or $singular_name ne $plural_name
l!l&&r!l&&!r
07980
MC/DC0%0/2
not $plural_name or $singular_name ne $plural_name
not $plural_name $singular_name ne $plural_name
Truth table33%1/3
not(A) or B
A= not $plural_nameB= $singular_name ne $plural_name
ABresult
1X1
011
000
1361 0 ▶ my $single_accessor = Sub::Name::subname $class_name ."::$singular_name" => sub {
Subroutine direct_property_meta: not called CC=12 SCAR=48.7
1362 0 my $self = shift;
1363 0 my $rule;
1364 0 ▶ $rule = $rule_resolver->($self) unless (defined $rule_template);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rule_template 0 0 0
1365 0 ▶ if ($rule_template) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rule_template) { } 0 0 0
1366 0 ▶ $rule = $rule_template->get_rule_for_values((map { $self->$_ } @property_names), @where_values) unless (defined $rule);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rule 0 0 0
1367 0 ▶ $params_prefix_resolver->() unless $params_prefix_resolved;
Branch: 1 branch
BranchTrueFalseTotal
unless $params_prefix_resolved 0 0 0
1368 0 ▶ unshift @_, @params_prefix if @_ == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 0 0
1369 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
1370 0 return my $obj = $r_class_name->get($rule->params_list,@_);
1371 }
1372 else {
1373 0 return my $obj = $r_class_name->get($rule);
1374 }
1375 }
1376 else {
1377 0 ▶ return unless $self->{$plural_name};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{$plural_name} 0 0 0
1378 0 ▶ return unless @_; # Can't compare our list to nothing...
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
1379 0 ▶ if (@_ > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 0 0 0
1380 0 Carp::croak "rule-based selection of single-item accessor not supported. Instead of single value, got @_";
1381 }
1382 0 ▶ unless (ref($self->{$plural_name}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $self->{$plural_name} eq "ARRAY") 0 0 0
1383 0 Carp::croak("${class_name}::$singular_name($_[0]): $plural_name does not contain an arrayref");
1384 }
1385 266 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1386 0 my @matches = grep { $_ eq $_[0] } @{ $self->{$plural_name} };
1387 0 ▶ return $matches[0] if @matches < 2;
Branch: 1 branch
BranchTrueFalseTotal
if @matches < 2 0 0 0
1388 0 return $self->context_return(@matches);
1389 }
1390 798 };
1391 798 Sub::Install::reinstall_sub({
1392 into => $class_name,
1393 as => $singular_name,
1394 code => $single_accessor,
1395 });
1396  
1397 # return now for reverse_as but not is_many
1398 798 ▶ unless ($plural_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($plural_name) 0 798 798
1399 0 return;
1400 }
1401 }
1402  
1403 798 my $rule_name = $self->rule_accessor_name_for_is_many_accessor($plural_name);
1404 0 ▶ my $rule_accessor = Sub::Name::subname $class_name ."::$rule_name" => sub {
Subroutine __direct_columnless_property_meta_rule: not called CC=4 SCAR=30.0
1405 0 my $self = shift;
1406 0 ▶ $rule_resolver->($self) unless ($rule_template);
Branch: 1 branch
BranchTrueFalseTotal
unless $rule_template 0 0 0
1407 0 ▶ unless ($rule_template) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rule_template) 0 0 0
1408 0 Carp::croak "No indirect rule available for locally-stored 'has-many' relationship";
1409 }
1410 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
1411 0 my $tmp_rule = $rule_template->get_rule_for_values((map { $self->$_ } @property_names), @where_values);
1412 0 return $r_class_name->define_boolexpr($tmp_rule->params_list, @_);
1413 }
1414 else {
1415 0 return $rule_template->get_rule_for_values((map { $self->$_ } @property_names),@where_values);
1416 }
1417 798 };
1418  
1419 798 Sub::Install::reinstall_sub({
1420 into => $class_name,
1421 as => $rule_name,
1422 code => $rule_accessor,
1423 });
1424  
1425 0 ▶ my $list_accessor = Sub::Name::subname $class_name ."::$plural_name" => sub {
Subroutine __ANON__: not called CC=10 SCAR=47.0
1426 0 my $self = shift;
1427 0 my $rule;
1428 0 ▶ $rule = $rule_resolver->($self) unless (defined $rule_template);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rule_template 0 0 0
1429 0 ▶ if ($rule_template) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rule_template) { } 0 0 0
1430 0 ▶ $rule = $rule_template->get_rule_for_values((map { $self->$_ } @property_names), @where_values) unless (defined $rule);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rule 0 0 0
1431 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
1432 0 return $UR::Context::current->query($r_class_name, $rule->params_list,@_);
1433 }
1434 else {
1435 0 return $UR::Context::current->query($r_class_name, $rule);
1436 }
1437 }
1438 else {
1439 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
1440 0 ▶ if (@_ != 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ != 1) { } 0 0 0
elsif (ref $_[0] ne 'ARRAY') { } 0 0 0
1441 0 Carp::croak "expected a single arrayref when setting a multi-value $class_name $plural_name! Got " . scalar(@_) . " args";
1442 } elsif ( ref($_[0]) ne 'ARRAY' ) {
1443 0 $self->{$plural_name} = [ $_[0] ];
1444 } else {
1445 0 $self->{$plural_name} = [ @{$_[0]} ];
1446 }
1447 0 return @{ $self->{$plural_name} };
1448 }
1449 else {
1450 0 ▶ return unless $self->{$plural_name};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{$plural_name} 0 0 0
1451 0 ▶ if (ref($self->{$plural_name}) ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{$plural_name} ne "ARRAY") 0 0 0
1452 0 Carp::carp("$class_name with id ".$self->id." does not hold an arrayref in its $plural_name property");
1453 0 $self->{$plural_name} = [ $self->{$plural_name} ];
1454 }
1455 0 return @{ $self->{$plural_name} };
1456 }
1457 }
1458 798 };
1459  
1460 798 Sub::Install::reinstall_sub({
1461 into => $class_name,
1462 as => $plural_name,
1463 code => $list_accessor,
1464 });
1465  
1466 798 Sub::Install::reinstall_sub({
1467 into => $class_name,
1468 as => $singular_name . '_list',
1469 code => $list_accessor,
1470 });
1471  
1472 798 my $arrayref_name = $self->arrayref_accessor_name_for_is_many_accessor($plural_name);
1473 0 ▶ my $arrayref_accessor = Sub::Name::subname $class_name ."::$arrayref_name" => sub {
Subroutine direct_property_meta_arrayref: not called CC=1 SCAR=6.9
1474 0 return [ $list_accessor->(@_) ];
1475 798 };
1476  
1477 798 Sub::Install::reinstall_sub({
1478 into => $class_name,
1479 as => $arrayref_name,
1480 code => $arrayref_accessor,
1481 });
1482  
1483 798 my $iterator_name = $self->iterator_accessor_name_for_is_many_accessor($plural_name);
1484 0 ▶ my $iterator_accessor = Sub::Name::subname $class_name ."::$iterator_name" => sub {
Subroutine __direct_id_property_meta_iterator: not called CC=6 SCAR=37.4
1485 0 my $self = shift;
1486 0 my $rule;
1487 0 ▶ $rule = $rule_resolver->($self) unless (defined $rule_template);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rule_template 0 0 0
1488 0 ▶ if ($rule_template) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rule_template) { } 0 0 0
1489 0 ▶ $rule = $rule_template->get_rule_for_values((map { $self->$_ } @property_names), @where_values) unless (defined $rule);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rule 0 0 0
1490 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
1491 0 return $r_class_name->create_iterator($rule->params_list,@_);
1492 } else {
1493 0 return UR::Object::Iterator->create_for_filter_rule($rule);
1494 }
1495 }
1496 else {
1497 0 ▶ return UR::Value::Iterator->create_for_value_arrayref($self->{$plural_name} || []);
Condition0%0/2
$self->{$plural_name} || []
l!l
00
MC/DC0%0/1
$self->{$plural_name} || []
$self->{$plural_name}
Truth table0%0/2
A
A= $self->{$plural_name}
Aresult
11
00
1498 }
1499 798 };
1500 798 Sub::Install::reinstall_sub({
1501 into => $class_name,
1502 as => $iterator_name,
1503 code => $iterator_accessor,
1504 });
1505  
1506 798 my $set_name = $self->set_accessor_name_for_is_many_accessor($plural_name);
1507 0 ▶ my $set_accessor = Sub::Name::subname $class_name ."::$set_name" => sub {
Subroutine direct_columnless_property_meta_set: not called CC=4 SCAR=30.0
1508 0 my $self = shift;
1509 0 my $rule;
1510 0 ▶ $rule = $rule_resolver->($self) unless (defined $rule_template);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rule_template 0 0 0
1511 0 ▶ if ($rule_template) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rule_template) { } 0 0 0
1512 0 ▶ $rule = $rule_template->get_rule_for_values((map { $self->$_ } @property_names),@where_values) unless (defined $rule);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rule 0 0 0
1513 0 return $r_class_name->define_set($rule->params_list,@_);
1514 }
1515 else {
1516 # this is a bit inside-out, but works for primitives
1517 0 my @members = $self->$plural_name;
1518 0 return UR::Value->define_set(id => \@members);
1519 }
1520 798 };
1521 798 Sub::Install::reinstall_sub({
1522 into => $class_name,
1523 as => $set_name,
1524 code => $set_accessor,
1525 });
1526  
1527 798 my $adder_method_name = $self->adder_name_for_is_many_accessor($plural_name);
1528 798 ▶ if ($class_name->can($adder_method_name)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class_name->can($adder_method_name)) 0 798 798
1529 0 $adder_method_name = '__' . $adder_method_name;
1530 }
1531 0 ▶ my $adder_method = Sub::Name::subname $class_name . '::' . $adder_method_name => sub {
Subroutine add_direct_property_meta: not called CC=13 SCAR=52.0
1532 # TODO: this handles only a single item when making objects: support a list of hashrefs
1533 0 my $self = shift;
1534 0 my $rule;
1535 0 ▶ $rule = $rule_resolver->($self) unless (defined $rule_template);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rule_template 0 0 0
1536 0 ▶ if ($rule_template) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rule_template) { } 0 0 0
1537 0 ▶ $params_prefix_resolver->() unless $params_prefix_resolved;
Branch: 1 branch
BranchTrueFalseTotal
unless $params_prefix_resolved 0 0 0
1538 0 ▶ unshift @_, @params_prefix if @_ == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 0 0
1539 0 ▶ $rule = $rule_template->get_rule_for_values((map { $self->$_ } @property_names), @where_values) unless (defined $rule);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rule 0 0 0
1540 0 $r_class_name->create($rule->params_list,@_);
1541 }
1542 else {
1543 0 ▶ if ($r_class_meta) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r_class_meta) { } 0 0 0
1544 0 my $obj;
1545 0 ▶ if (@_ == 1 and $_[0]->isa($r_class_name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and $_[0]->isa($r_class_name)) { } 0 0 0
Condition0%0/3
@_ == 1 and $_[0]->isa($r_class_name)
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and $_[0]->isa($r_class_name)
@_ == 1 $_[0]->isa($r_class_name)
Truth table0%0/3
A and B
A= @_ == 1B= $_[0]->isa($r_class_name)
ABresult
0X0
100
111
1546 0 $obj = $_[0];
1547 }
1548 else {
1549 0 $obj = $r_class_name->create(@where,@_);
1550 0 ▶ unless ($obj) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($obj) 0 0 0
1551 0 $self->error_message("Failed to add $singular_name:" . $r_class_name->error_message);
1552 0 return;
1553 }
1554 }
1555 0 ▶ push @{ $self->{$plural_name} ||= [] }, $obj;
Condition0%0/2
$self->{$plural_name} ||= []
l!l
00
MC/DC0%0/1
$self->{$plural_name} ||= []
$self->{$plural_name}
Truth table0%0/2
A
A= $self->{$plural_name}
Aresult
11
00
1556 }
1557 else {
1558 0 ▶ if (@_ != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ != 1) 0 0 0
1559 0 Carp::croak "$class_name $adder_method_name expects a single value to add. Got " . scalar(@_) . " args";
1560 }
1561 0 ▶ push @{ $self->{$plural_name} ||= [] }, $_[0];
Condition0%0/2
$self->{$plural_name} ||= []
l!l
00
MC/DC0%0/1
$self->{$plural_name} ||= []
$self->{$plural_name}
Truth table0%0/2
A
A= $self->{$plural_name}
Aresult
11
00
1562 0 return $_[0];
1563 }
1564 }
1565 798 };
1566 798 Sub::Install::reinstall_sub({
1567 into => $class_name,
1568 as => $adder_method_name,
1569 code => $adder_method,
1570 });
1571  
1572 798 my $remover_method_name = $self->remover_name_for_is_many_accessor($plural_name);
1573 798 ▶ if ($class_name->can($remover_method_name)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class_name->can($remover_method_name)) 0 798 798
1574 0 $remover_method_name = '__' . $remover_method_name;
1575 }
1576 0 ▶ my $remover_method = Sub::Name::subname $class_name . '::' . $remover_method_name => sub {
Subroutine remove_direct_columnless_property_meta: not called CC=21 SCAR=61.4
1577 0 my $self = shift;
1578 0 my $rule;
1579 0 ▶ $rule = $rule_resolver->($self) unless (defined $rule_template);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rule_template 0 0 0
1580 0 ▶ if ($rule_template) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rule_template) { } 0 0 0
1581 # an id-linked "has-many"
1582 0 ▶ $rule = $rule_template->get_rule_for_values((map { $self->$_ } @property_names), @where_values) unless (defined $rule);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rule 0 0 0
1583 0 ▶ $params_prefix_resolver->() unless $params_prefix_resolved;
Branch: 1 branch
BranchTrueFalseTotal
unless $params_prefix_resolved 0 0 0
1584 0 my @matches;
1585 0 ▶ if (@_ == 1 and ref($_[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0]) { } 0 0 0
Condition0%0/3
@_ == 1 and ref $_[0]
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and ref $_[0]
@_ == 1 ref $_[0]
Truth table0%0/3
A and B
A= @_ == 1B= ref $_[0]
ABresult
0X0
100
111
1586 # the object to remove was passed-in
1587 0 ▶ unless ($rule->evaluate($_[0])) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rule->evaluate($_[0])) 0 0 0
1588 0 Carp::croak "Object " . $_[0]->__display_name__ . " is not a member of the $singular_name set!";
1589 }
1590 0 @matches = ($_[0]);
1591 }
1592 else {
1593 # the parameters to find objects to remove were passed-in
1594 0 ▶ unshift @_, @params_prefix if @_ == 1; # a single "id" is the remainder of the id of the object
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 0 0
1595 0 @matches = $r_class_name->get($rule->params_list,@_);
1596 }
1597 0 my $trans = UR::Context::Transaction->begin;
1598 @matches = map {
1599 0 ▶ $_->delete or Carp::croak "Error deleting $r_class_name " . $_->id . " for $remover_method_name!: " . $_->error_message;
Condition0%0/2
$_->delete || Carp::croak("Error deleting $r_class_name " . $_->id . " for $remover_method_name!: " . $_->error_message)
l!l
00
MC/DC0%0/1
$_->delete || Carp::croak("Error deleting $r_class_name " . $_->id . " for $remover_method_name!: " . $_->error_message)
$_->delete
Truth table0%0/2
A
A= $_->delete
Aresult
11
00
1600 } @matches;
1601 0 $trans->commit;
1602 0 return @matches;
1603 }
1604 else {
1605 # direct storage in an arrayref
1606 0 ▶ $self->{$plural_name} ||= [];
Condition0%0/2
$self->{$plural_name} ||= []
l!l
00
MC/DC0%0/1
$self->{$plural_name} ||= []
$self->{$plural_name}
Truth table0%0/2
A
A= $self->{$plural_name}
Aresult
11
00
1607 0 ▶ if ($r_class_meta) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r_class_meta) { } 0 0 0
1608 # object
1609 0 my @remove;
1610 my @keep;
1611 0 my $rule = $r_class_name->define_boolexpr(@_);
1612 0 for my $value (@{ $self->{$plural_name} }) {
1613 0 ▶ if ($rule->evaluate($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rule->evaluate($value)) { } 0 0 0
1614 0 push @keep, $value;
1615 }
1616 else {
1617 0 push @remove, $value;
1618 }
1619 }
1620 0 ▶ if (@remove) {
Branch: 1 branch
BranchTrueFalseTotal
if (@remove) 0 0 0
1621 0 @{ $self->{$plural_name} } = @keep;
1622 }
1623 0 return @remove;
1624 }
1625 else {
1626 # value (or non-ur object)
1627 0 ▶ if (@_ == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1) { } 0 0 0
elsif (@_ == 0) { } 0 0 0
1628 # remove specific value
1629 0 my $removed;
1630 0 my $n = 0;
1631 0 for my $value (@{ $self->{$plural_name} }) {
1632 0 ▶ if ($value eq $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value eq $_[0]) 0 0 0
1633 0 $removed = splice(@{ $self->{$plural_name} }, $n, 1);
1634 0 ▶ Carp::croak("Internal object inconsistency removing value '$value'. Value '$removed' was removed instead!?") unless $removed eq $value;
Branch: 1 branch
BranchTrueFalseTotal
unless $removed eq $value 0 0 0
1635 0 return $removed;
1636 }
1637 0 $n++;
1638 }
1639 0 Carp::croak("Failed to find item $_[0] in $class_name $plural_name. Object has " . scalar(@{$self->{$plural_name}}) . " values: ".join(', ', @{$self->{$plural_name}}));
1640 }
1641 elsif (@_ == 0) {
1642 # remove all if no params are specified
1643 0 ▶ @{ $self->{$plural_name} ||= [] } = ();
Condition0%0/2
$self->{$plural_name} ||= []
l!l
00
MC/DC0%0/1
$self->{$plural_name} ||= []
$self->{$plural_name}
Truth table0%0/2
A
A= $self->{$plural_name}
Aresult
11
00
1644 }
1645 else {
1646 0 Carp::croak("$class_name $remover_method_name should be called with zero or one arg, got ".scalar(@_));
1647 }
1648 }
1649 }
1650 798 };
1651  
1652 # check here
1653 798 Sub::Install::reinstall_sub({
1654 into => $class_name,
1655 as => $remover_method_name,
1656 code => $remover_method,
1657 });
1658  
1659 }
1660  
1661 266 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
1662  
1663 11966 ▶sub initialize_direct_accessors {
Subroutine initialize_direct_accessors: called CC=39 SCAR=52.5
Pod undocumented
1664 11966 my $self = shift;
1665 11966 my $class_name = $self->{class_name};
1666  
1667 11966 my %id_property_names;
1668 11966 for my $property_name (@{ $self->{id_by} }) {
1669 3990 $id_property_names{$property_name} = 1;
1670 3990 ▶ next if $property_name eq "id";
Branch: 1 branch
BranchTrueFalseTotal
if $property_name eq "id" 266 3724 3990
1671 }
1672  
1673 11966 my %dimensions_by_fk;
1674 11966 for my $property_name (sort keys %{ $self->{has} }) {
1675 48408 my $property_data = $self->{has}{$property_name};
1676 48408 ▶ if ($property_data->{is_dimension}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($property_data->{"is_dimension"}) 0 48408 48408
1677 0 my $id_by = $property_data->{id_by};
1678 0 ▶ unless ($id_by) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($id_by) 0 0 0
1679 0 Carp::croak "No id_by specified for dimension $property_name?";
1680 }
1681 0 ▶ if (@$id_by != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$id_by != 1) 0 0 0
1682 0 Carp::croak "The id_by specified for dimension $property_name must list a single property name!";
1683 }
1684  
1685 0 my $dimension_class_name = $property_data->{data_type};
1686 0 $dimensions_by_fk{$id_by->[0]} = $dimension_class_name;
1687  
1688 0 my $ref_class_meta = $dimension_class_name->__meta__;
1689 0 my %remote_id_properties = map { $_ => 1 } $ref_class_meta->id_property_names;
1690 0 my @non_id_properties = grep { not $remote_id_properties{$_} } $ref_class_meta->all_property_names;
1691 0 for my $expected_delegate_property_name (@non_id_properties) {
1692 0 ▶ unless ($self->{has}{$expected_delegate_property_name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"has"}{$expected_delegate_property_name}) 0 0 0
1693 0 $self->{has}{$expected_delegate_property_name} = {
1694 $self->_normalize_property_description(
1695 $expected_delegate_property_name,
1696 { via => $property_name, to => $expected_delegate_property_name, implied_by => $property_name }
1697 )
1698 }
1699 }
1700 }
1701 }
1702 }
1703  
1704 11966 for my $pname (sort keys %{ $self->{has} }) {
1705 48408 my $property_name = $pname; # mutable
1706 48408 my $accessor_name = $pname;
1707  
1708 48408 my $property_data = $self->{has}{$property_name};
1709  
1710 # handle aliases
1711 # the underlying property_name and data will change, though the accessor will not
1712 48408 my $n = 0;
1713 48408 ▶ while ($property_data->{via} and $property_data->{via} eq '__self__') {
Branch: 1 branch
BranchTrueFalseTotal
if ($property_data->{"via"} and $property_data->{"via"} eq "__self__") 0 48408 48408
Condition66%2/3
$property_data->{"via"} and $property_data->{"via"} eq "__self__"
!ll&&!rl&&r
38300101080
MC/DC0%0/2
$property_data->{"via"} and $property_data->{"via"} eq "__self__"
$property_data->{"via"} $property_data->{"via"} eq "__self__"
Truth table66%2/3
A and B
A= $property_data->{"via"}B= $property_data->{"via"} eq "__self__"
ABresult
0X0
100
111
1714 0 $property_name = $property_data->{to};
1715 0 $property_data = $self->{has}{$property_name};
1716 0 ▶ unless ($property_data) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($property_data) 0 0 0
1717 0 Carp::confess("Property $accessor_name is an alias for $property_name, which does not exist!")
1718 }
1719 0 ▶ if ($n > 100) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n > 100) 0 0 0
1720 0 Carp::confess("Deep recursion in property aliases behind $accessor_name!");
1721 }
1722 }
1723  
1724 48408 my $column_name = $property_data->{column_name};
1725 48408 my $is_transient = $property_data->{is_transient};
1726 48408 my $where = $property_data->{where};
1727  
1728 48408 do {
1729 # Handle the case where the software module has an explicit
1730 # override for one of the accessors.
1731 266 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1732 48408 my $isa = \@{ $class_name . "::ISA" };
1733 48408 my @old_isa = @$isa;
1734 48408 @$isa = ();
1735 48408 ▶ if ($class_name->can($accessor_name)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class_name->can($accessor_name)) 5054 43354 48408
1736 #warn "property $class_name $accessor_name exists!";
1737 5054 $accessor_name = "__$accessor_name";
1738 }
1739 48408 @$isa = @old_isa;
1740 };
1741  
1742 48408 ▶ unless ($accessor_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($accessor_name) 0 48408 48408
1743 0 Carp::croak("No accessor name for property '$property_name' of class $class_name");
1744 }
1745  
1746 48408 my $accessor_type;
1747 48408 my @calculation_fields = (qw/calculate calc_perl calc_sql calculate_from/);
1748 48408 ▶ if (my $id_by = $property_data->{id_by}) {
Branch: 7 branches
BranchTrueFalseTotal
if (my $id_by = $property_data->{'id_by'}) { } 2128 46280 48408
elsif ($property_data->{'is_calculated'} and not $property_data->{'is_mutable'}) { } 0 46280 46280
elsif (my $via = $property_data->{'via'}) { } 10108 36172 46280
elsif (my $calculate = $property_data->{'calculate'}) { } 798 35374 36172
elsif (my $calculate_sql = $property_data->{'calculate_sql'}) { } 0 35374 35374
elsif ($property_data->{'is_many'} or $property_data->{'reverse_as'}) { } 798 34576 35374
elsif ($property_data->{'is_classwide'}) { } 0 34576 34576
1749 2128 my $r_class_name = $property_data->{data_type};
1750 #$self->mk_id_based_object_accessor($class_name, $accessor_name, $id_by, $r_class_name,$where);
1751 2128 my $id_class_by = $property_data->{id_class_by};
1752 2128 ▶ if ($property_data->{access_as} and $property_data->{access_as} eq 'auto') {
Branch: 1 branch
BranchTrueFalseTotal
if ($property_data->{'access_as'} and $property_data->{'access_as'} eq 'auto') { } 0 2128 2128
Condition33%1/3
$property_data->{"access_as"} and $property_data->{"access_as"} eq "auto"
!ll&&!rl&&r
212800
MC/DC0%0/2
$property_data->{"access_as"} and $property_data->{"access_as"} eq "auto"
$property_data->{"access_as"} $property_data->{"access_as"} eq "auto"
Truth table33%1/3
A and B
A= $property_data->{"access_as"}B= $property_data->{"access_as"} eq "auto"
ABresult
0X0
100
111
1753 0 $self->mk_id_based_flex_accessor($class_name, $accessor_name, $id_by, $r_class_name,$where, $id_class_by);
1754 0 ▶ $self->mk_id_based_object_accessor($class_name, $accessor_name . ($property_data->{is_many} ? '_objs' : '_obj'), $id_by, $r_class_name,$where, $id_class_by);
Branch: 1 branch
BranchTrueFalseTotal
$property_data->{'is_many'} ? : 0 0 0
1755 }
1756 else {
1757 2128 $self->mk_id_based_object_accessor($class_name, $accessor_name, $id_by, $r_class_name,$where, $id_class_by);
1758 }
1759 }
1760 ▶ elsif ($property_data->{'is_calculated'} and ! $property_data->{'is_mutable'}) {# and $property_data->{'column_name'}) {
Condition66%2/3
$property_data->{"is_calculated"} and not $property_data->{"is_mutable"}
!ll&&!rl&&r
4521610640
MC/DC0%0/2
$property_data->{"is_calculated"} and not $property_data->{"is_mutable"}
$property_data->{"is_calculated"} not $property_data->{"is_mutable"}
Truth table66%2/3
A and not(B)
A= $property_data->{"is_calculated"}B= not $property_data->{"is_mutable"}
ABresult
0X0
100
111
1761 # For calculated + immutable properties, their calculation function is called
1762 # by UR::Context->create_entity(), which then stores the value in the object's
1763 # hash. So, the accessor just needs to pull the data like a regular r/o accessor
1764 #$self->mk_ro_accessor($class_name, $accessor_name, $property_data->{'column_name'});
1765 $self->mk_calculation_accessor(
1766 $class_name,
1767 $accessor_name,
1768 $property_data->{'calculate'},
1769 $property_data->{calculate_from},
1770 $property_data->{calculate_params},
1771 1, # the value should be cached
1772 0 $property_data->{'column_name'},
1773 );
1774 }
1775 elsif (my $via = $property_data->{via}) {
1776 10108 ▶ my $to = $property_data->{to} || $property_data->{property_name};
Condition33%1/3
$property_data->{'to'} || $property_data->{'property_name'}
l!l&&r!l&&!r
1010800
MC/DC0%0/2
$property_data->{'to'} || $property_data->{'property_name'}
$property_data->{'to'} $property_data->{'property_name'}
Truth table33%1/3
A || B
A= $property_data->{'to'}B= $property_data->{'property_name'}
ABresult
1X1
011
000
1777 10108 ▶ if ($via eq '__self__') {
Branch: 1 branch
BranchTrueFalseTotal
if ($via eq "__self__") 0 10108 10108
1778 0 Carp::croak "aliases should be caught above!";
1779  
1780 }
1781 10108 ▶ if ($property_data->{is_mutable}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($property_data->{'is_mutable'}) { } 0 10108 10108
1782 0 my $singular_name;
1783 0 ▶ if ($property_data->{'is_many'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($property_data->{"is_many"}) 0 0 0
1784 0 require Lingua::EN::Inflect;
1785 0 $singular_name = Lingua::EN::Inflect::PL_V($accessor_name);
1786 }
1787 0 ▶ $self->mk_indirect_rw_accessor($class_name,$accessor_name,$via,$to,$where,$property_data->{'is_many'} && $singular_name, $property_name);
Condition0%0/3
$property_data->{'is_many'} && $singular_name
!ll&&!rl&&r
000
MC/DC0%0/2
$property_data->{'is_many'} && $singular_name
$property_data->{'is_many'} $singular_name
Truth table0%0/3
A && B
A= $property_data->{'is_many'}B= $singular_name
ABresult
0X0
100
111
1788 }
1789 else {
1790 10108 $self->mk_indirect_ro_accessor($class_name,$accessor_name,$via,$to,$where);
1791 }
1792 }
1793 elsif (my $calculate = $property_data->{calculate}) {
1794 $self->mk_calculation_accessor(
1795 $class_name,
1796 $accessor_name,
1797 $property_data->{calculate},
1798 $property_data->{calculate_from},
1799 $property_data->{calculate_params},
1800 $property_data->{is_constant},
1801 $property_data->{column_name},
1802 798 );
1803 }
1804 elsif (my $calculate_sql = $property_data->{'calculate_sql'}) {
1805 # The data gets filled in by the object loader behind the scenes.
1806 # To the user, it's a read-only property
1807 0 $self->mk_ro_accessor($class_name, $accessor_name, $calculate_sql);
1808  
1809 }
1810 ▶ elsif ($property_data->{is_many} or $property_data->{reverse_as}){
Condition66%2/3
$property_data->{"is_many"} or $property_data->{"reverse_as"}
l!l&&r!l&&!r
798034576
MC/DC50%1/2
$property_data->{"is_many"} or $property_data->{"reverse_as"}
$property_data->{"is_many"} $property_data->{"reverse_as"}
Truth table66%2/3
A or B
A= $property_data->{"is_many"}B= $property_data->{"reverse_as"}
ABresult
1X1
011
000
1811 798 my $reverse_as = $property_data->{reverse_as};
1812 798 my $r_class_name = $property_data->{data_type};
1813 798 my $singular_name;
1814 my $plural_name;
1815 798 ▶ if ($property_data->{is_many}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($property_data->{'is_many'}) { } 798 0 798
1816 798 $plural_name = $accessor_name;
1817 798 $singular_name = $self->singular_accessor_name_for_is_many_accessor($accessor_name);
1818 }
1819 else {
1820 0 $singular_name = $accessor_name;
1821 }
1822 798 $self->mk_object_set_accessors($class_name, $singular_name, $plural_name, $reverse_as, $r_class_name, $where);
1823 }
1824 elsif ($property_data->{'is_classwide'}) {
1825 my($value, $column_name, $is_transient, $calc_default)
1826 0 = @$property_data{'default_value','column_name','is_transient', 'calculated_default'};
1827 0 ▶ if ($property_data->{'is_constant'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($property_data->{'is_constant'}) { } 0 0 0
1828 0 $self->mk_ro_class_accessor($class_name,$accessor_name,$column_name,$value, $calc_default);
1829 } else {
1830 0 $self->mk_rw_class_accessor($class_name,$accessor_name,$column_name,$is_transient,$value, $calc_default);
1831 }
1832 }
1833 else {
1834 # Just use key/value pairs in the hash for normal
1835 # table stuff, and also non-database stuff.
1836  
1837 #if ($column_name) {
1838 # push @$props, $property_name;
1839 # push @$cols, $column_name;
1840 #}
1841  
1842 34576 my $maker;
1843 34576 ▶ if ($id_property_names{$property_name} or not $property_data->{is_mutable}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id_property_names{$property_name} or not $property_data->{'is_mutable'}) { } 4522 30054 34576
Condition100%3/3
$id_property_names{$property_name} or not $property_data->{"is_mutable"}
l!l&&r!l&&!r
399053230054
MC/DC100%2/2
$id_property_names{$property_name} or not $property_data->{"is_mutable"}
$id_property_names{$property_name} not $property_data->{"is_mutable"}
Truth table100%3/3
A or not(B)
A= $id_property_names{$property_name}B= not $property_data->{"is_mutable"}
ABresult
1X1
011
000
1844 4522 $maker = 'mk_ro_accessor';
1845 }
1846 else {
1847 30054 $maker = 'mk_rw_accessor';
1848 }
1849 34576 $self->$maker($class_name, $accessor_name, $column_name, $property_name,$is_transient);
1850 }
1851 }
1852  
1853 # right now we just stomp on the default accessors constructed above where they are:
1854 # 1. the fk behind a dimensional relationships
1855 # 2. the indirect properties created for the dimensional relationship
1856 11966 for my $dimension_id (keys %dimensions_by_fk) {
1857 0 my $dimension_class_name = $dimensions_by_fk{$dimension_id};
1858 0 my $ref_class_meta = $dimension_class_name->__meta__;
1859 0 my %remote_id_properties = map { $_ => 1 } $ref_class_meta->id_property_names;
1860 0 my @non_id_properties = grep { not $remote_id_properties{$_} } $ref_class_meta->all_property_names;
1861 0 for my $added_property_name (@non_id_properties) {
1862 0 $self->mk_dimension_delegate_accessors($dimension_id,$dimension_class_name, \@non_id_properties, $added_property_name);
1863 }
1864 0 $self->mk_dimension_identifying_accessor($dimension_id,$dimension_class_name, \@non_id_properties);
1865 }
1866  
1867 11966 return 1;
1868 }
1869  
1870  
1871 266 1;
1872  
1873 =pod
1874  
1875 =head1 NAME
1876  
1877 UR::Object::Type::AccessorWriter - Helper module for UR::Object::Type responsible for creating accessors for properties
1878  
1879 =head1 DESCRIPTION
1880  
1881 Subroutines within this module actually live in the UR::Object::Type
1882 namespace; this module is just a convienent place to collect them. The
1883 class initializer uses these subroutines when it's time to create accessor
1884 methods for a newly defined class. Each accessor is implemented by a closure
1885 that is then assigned a name by Sub::Name and inserted into the defined
1886 class's namespace by Sub::Install.
1887  
1888 =head1 METHODS
1889  
1890 =over 4
1891  
1892 =item initialize_direct_accessors
1893  
1894 $classobj->initialize_direct_accessors();
1895  
1896 This is the entry point into the accessor writing system. It inspects each
1897 item in the 'has' key of the class object's hashref, and creates methods for
1898 each property.
1899  
1900 =item mk_rw_accessor
1901  
1902 $classobj->mk_rw_accessor($class_name, $accessor_name, $column_name, $property_name, $is_transient);
1903  
1904 Creates a mutable accessor named $accessor_name which stores its value in
1905 the $property_name key of the object's hashref.
1906  
1907 =item mk_ro_accessor
1908  
1909 $classobj->mk_ro_accessor($class_name, $accessor_name, $column_name, $property_name);
1910  
1911 Creates a read-only accessor named $accessor_name which retrieves its value
1912 in the $property_name key of the object's hashref. If the method is used
1913 as a mutator by passing in a value to the method, it will throw an exception
1914 with Carp::croak.
1915  
1916 =item mk_id_based_object_accessor
1917  
1918 $classobj->mk_id_based_object_accessor($class_name, $accessor_name, $id_by,
1919 $r_class_name, $where);
1920  
1921 Creates an object accessor named $accessor_name. It returns objects of type
1922 $r_class_name, id-ed by the parameters named in the $id_by arrayref. $where
1923 is an optional listref of additional filters to apply when retrieving
1924 objects.
1925  
1926 The behavior of the created accessor depends on the number of parameters
1927 passed to it. For 0 params, it retrieves the object pointed to by
1928 $r_class_name and $id_by. For 1 param, it looks up the ID param values
1929 of the passed-in object-parameter, and reassigns value stored in the $id_by
1930 properties of the acted-upon object, effectively acting as a mutator.
1931  
1932 For more than 1 param, the additional parameters are taken as
1933 properties/values to filter the returned objects on
1934  
1935 =item mk_indirect_ro_accessor
1936  
1937 $classobj->mk_indirect_ro_accessor($class_name, $accessor_name, $via, $to, $where);
1938  
1939 Creates a read-only via accessor named $accessor_name. Its value is
1940 obtained by calling the object accessor named $via, and then calling
1941 the method $to on that object. The optional $where listref is used
1942 as additional filters when calling $via.
1943  
1944 =item mk_indirect_rw_accessor
1945  
1946 $classobj->mk_indirect_rw_accessor($class_name, $accessor_name, $via, $to,
1947 $where, $singular_name);
1948  
1949 Creates a via accessor named $accessor_name that is able to change the
1950 property it points to with $to when called as a mutator. If the $to property
1951 on the remote object is an ID property of its class, it deletes the refered-to
1952 object and creates a new one with the appropriate properties. Otherwise, it
1953 updates the $to property on the refered-to object.
1954  
1955 =item mk_calculation_accessor
1956  
1957 $classobj->mk_calculation_accessor($class_name, $accessor_name, $calculation_src,
1958 $calculate_from, $params, $is_constant, $column_name);
1959  
1960 Creates a calculated accessor called $accessor_name. If the $is_constant
1961 flag is true, then the accessor runs the calculation once, caches the result,
1962 and returns that result for subsequent calls to the accessor.
1963  
1964 $calculation_src can be one of: coderef, string containing Perl code, or
1965 the name of a module under UR::Object::Type::AccessorWriter which has a
1966 method called C<calculate>. If $calculation_src is empty, then $accessor_name
1967 must be the name of an already-existing subroutine in the class's namespace.
1968  
1969 =item mk_dimension_delegate_accessors
1970  
1971 =item mk_dimension_identifying_accessor
1972  
1973 These create accessors for dealing with dimension tables in OLAP-type schemas.
1974 They need more documentation.
1975  
1976 =item mk_rw_class_accessor
1977  
1978 $classobj->mk_rw_class_accessor($class_name, $accessor_name, $column_name, $is_transient, $variable_value);
1979  
1980 Creates a read-write accessor called $accessor_name which stores its value
1981 in a scalar captured by the accessor's closure. Since the closure is
1982 inserted into the class's namespace, all instances of the class share the
1983 same closure (and therefore the same scalar), and the property effectively
1984 acts as a class-wide property.
1985  
1986 =item mk_ro_class_accessor
1987  
1988 $classobj->mk_ro_class_accessor($class_name, $accessor_name, $column_name, $variable_value);
1989  
1990 Creates a read-only accessor called $accessor_name which retrieves its value
1991 from a scalar captured by the accessor's closure. The value is initialized
1992 to $variable_value. If called as a mutator, it throws an exception through
1993 Carp::croak
1994  
1995 =back
1996  
1997 =head1 SEE ALSO
1998  
1999 UR::Object::Type::AccessorWriter, UR::Object::Type
2000  
2001 =cut
« lib/UR/Context/Transaction.pm ↑ Summary lib/UR/Object/Type/InternalAPI.pm »