lib/UR/Object/Type/Initializer.pm

filter: Statementstmt 54.7% 493 / 900 Branchbran 40.5% 184 / 454 Conditioncond 40.4% 99 / 245 MC/DCmcdc 15.1% 21 / 139 Subroutinesub 87.5% 42 / 48 Podpod 20.0% 1 / 5 totaltotal 46.9% 840 / 1791 CC 357 SCAR 61.2
CC
357
Cov
49%
_complete_class_meta_object_definitions
1916.4
_normalize_class_description_impl
577.4
generate
382.4
CRAP 454.0
« blib/lib/UR/DataSource/RDBMS.pm ↑ Summary blib/lib/UR/Change.pm »
1 # This line forces correct deployment by some tools.
2 package UR::Object::Type::Initializer;
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 143 require UR;
9  
10 266 ▶use UR::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 266 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.2
13 # Perl 5.10 did not require mro in order to call get_mro but it looks
14 # like that was "fixed" in newer version.
15 266 ▶ if ($^V ge v5.9.5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^V ge v5.9.5) 266 0 266
16 266 eval "require mro";
17 }
18 };
19  
20 143 our $VERSION = "0.47"; # UR $VERSION;
21  
22 266 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
23 266 ▶use Sub::Name ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24 266 ▶use Sub::Install ();
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 # keys are class property names (like er_role, is_final, etc) and values are
27 # the default value to use if it's not specified in the class definition
28 #
29 # For most classes, this kind of thing is handled by the default_value attribute on
30 # a class' property. For bootstrapping reasons, the default values for the
31 # properties of UR::Object::Type' class need to be listed here as well. If
32 # any of these change, or new default valued items are added, be sure to also
33 # update the class definition for UR::Object::Type (which really lives in UR.pm
34 # for the moment)
35 143 %UR::Object::Type::defaults = (
36 er_role => 'entity',
37 is_final => 0,
38 is_singleton => 0,
39 is_transactional => 1,
40 is_mutable => 1,
41 is_many => 0,
42 is_abstract => 0,
43 subclassify_by_version => 0,
44 );
45  
46 # All those same comments also apply to UR::Object::Property's properties
47 143 %UR::Object::Property::defaults = (
48 is_optional => 0,
49 is_transient => 0,
50 is_constant => 0,
51 is_volatile => 0,
52 is_classwide => 0,
53 is_delegated => 0,
54 is_calculated => 0,
55 is_mutable => undef,
56 is_transactional => 1,
57 is_many => 0,
58 is_numeric => 0,
59 is_specified_in_module_header => 0,
60 is_deprecated => 0,
61 position_in_module_header => -1,
62 doc_position => -1,
63 is_undocumented => 0,
64 );
65  
66 143 @UR::Object::Type::meta_id_ref_shared_properties = (
67 qw/
68 is_optional
69 is_transient
70 is_constant
71 is_volatile
72 is_classwide
73 is_transactional
74 is_abstract
75 is_concrete
76 is_final
77 is_many
78 is_deprecated
79 is_undocumented
80 /
81 );
82  
83 143 %UR::Object::Type::converse = (
84 required => 'optional',
85 abstract => 'concrete',
86 one => 'many',
87 );
88  
89 # These classes are used to define an object class.
90 # As such, they get special handling to bootstrap the system.
91  
92 143 our %meta_classes = map { $_ => 1 }
93 qw/
94 UR::Object
95 UR::Object::Type
96 UR::Object::Property
97 /;
98  
99 143 our $bootstrapping = 1;
100 143 our @partially_defined_classes;
101  
102 # When copying the object hash to create its db_committed, these keys should be removed because
103 # they contain things like coderefs
104 143 our @keys_to_delete_from_db_committed = qw( id db_committed _id_property_sorter get_composite_id_resolver get_composite_id_decomposer );
105  
106 # Stages of Class Initialization
107 #
108 # define() is called to indicate the class structure (create() may also be called by the db sync command to make new classes)
109 #
110 # the parameters to define()/create() are normalized by _normalize_class_description()
111 #
112 # a basic functional class meta object is created by _define_minimal_class_from_normalized_class_description()
113 #
114 # accessors are created
115 #
116 # if we're still bootstrapping:
117 #
118 # the class is stashed in an array so the post-bootstrapping stages can be done in bulk
119 #
120 # we exit define()
121 #
122 # if we're done bootstrapping:
123 #
124 # _inform_all_parent_classes_of_newly_loaded_subclass() sets up an internal map of known subclasses of each base class
125 #
126 # _complete_class_meta_object_definitions() decomposes the definition into normalized objects
127 #
128  
129 11966 ▶sub __define__ {
Subroutine __define__: called CC=10 SCAR=26.5
130 11966 my $class = shift;
131 11966 my $desc = $class->_normalize_class_description(@_);
132  
133 11966 ▶ my $class_name = $desc->{class_name} ||= (caller(0))[0];
Condition33%1/3
$desc->{"class_name"} ||= (caller 0)[0]
l!l&&r!l&&!r
1196600
MC/DC0%0/2
$desc->{"class_name"} ||= (caller 0)[0]
$desc->{"class_name"} (caller 0)[0]
Truth table33%1/3
A ||= B
A= $desc->{"class_name"}B= (caller 0)[0]
ABresult
1X1
011
000
134 11966 $desc->{class_name} = $class_name;
135  
136 11966 my $self;
137  
138 11966 my %params = $class->_construction_params_for_desc($desc);
139 11966 my $meta_class_name;
140 11966 ▶ if (%params) {
Branch: 1 branch
BranchTrueFalseTotal
if (%params) { } 5584 6382 11966
141 5584 $self = __PACKAGE__->__define__(%params);
142 5584 ▶ return unless $self;
Branch: 1 branch
BranchTrueFalseTotal
unless $self 0 5584 5584
143 5584 $meta_class_name = $params{class_name};
144 }
145 else {
146 6382 $meta_class_name = __PACKAGE__;
147 }
148  
149 11966 $self = $UR::Context::all_objects_loaded->{$meta_class_name}{$class_name};
150 11966 ▶ if ($self) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self) 0 11966 11966
151 #$DB::single = 1;
152 #Carp::cluck("Re-defining class $class_name? Found $meta_class_name with id '$class_name'");
153 0 return $self;
154 }
155  
156 11966 $self = $class->_make_minimal_class_from_normalized_class_description($desc);
157 11966 ▶ Carp::confess("Failed to define class $class_name!") unless $self;
Branch: 1 branch
BranchTrueFalseTotal
unless $self 0 11966 11966
158  
159 # we do this for define() but not create()
160 11966 my %db_committed = %$self;
161 11966 delete @db_committed{@keys_to_delete_from_db_committed};
162 11966 $self->{'db_committed'} = \%db_committed;
163  
164 11966 ▶ $self->_initialize_accessors_and_inheritance
Branch: 1 branch
BranchTrueFalseTotal
$self->_initialize_accessors_and_inheritance or Carp::confess("Error initializing accessors for $class_name!") 11966 0 11966
165 or Carp::confess("Error initializing accessors for $class_name!");
166  
167 11966 ▶ if ($bootstrapping) {
Branch: 1 branch
BranchTrueFalseTotal
if ($UR::Object::Type::bootstrapping) { } 11966 0 11966
168 11966 push @partially_defined_classes, $self;
169 }
170 else {
171 0 ▶ unless ($self->_inform_all_parent_classes_of_newly_loaded_subclass()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_inform_all_parent_classes_of_newly_loaded_subclass) 0 0 0
172 0 Carp::confess(
173 "Failed to link to parent classes to complete definition of class $class_name!"
174 . $class->error_message
175 );
176 }
177 0 ▶ unless ($self->_complete_class_meta_object_definitions()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_complete_class_meta_object_definitions) 0 0 0
178 #$DB::single = 1;
179 0 $self->_complete_class_meta_object_definitions();
180 0 Carp::confess(
181 "Failed to complete definition of class $class_name!"
182 . $class->error_message
183 );
184 }
185 }
186  
187 11966 $self->_inform_roles_of_new_class();
188  
189 11966 return $self;
190 }
191  
192  
193 0 ▶sub create {
Subroutine create: not called CC=9 SCAR=42.8
Pod documented
194 # this is typically only used by code which intendes to autogenerate source code
195 # it will lead to the writing of a Perl module upon commit.
196 0 my $class = shift;
197 0 my $desc = $class->_normalize_class_description(@_);
198  
199 0 ▶ my $class_name = $desc->{class_name} ||= (caller(0))[0];
Condition0%0/3
$desc->{"class_name"} ||= (caller 0)[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
$desc->{"class_name"} ||= (caller 0)[0]
$desc->{"class_name"} (caller 0)[0]
Truth table0%0/3
A ||= B
A= $desc->{"class_name"}B= (caller 0)[0]
ABresult
1X1
011
000
200 0 my $meta_class_name = $desc->{meta_class_name};
201  
202 266 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
203 0 ▶ unless (
Branch: 1 branch
BranchTrueFalseTotal
unless ($meta_class_name eq __PACKAGE__ or scalar @{$meta_class_name . '::ISA';} and $meta_class_name->isa(__PACKAGE__)) 0 0 0
Condition0%0/6
$meta_class_name eq __PACKAGE__ or scalar @{$meta_class_name . '::ISA';} and $meta_class_name->isa(__PACKAGE__)
l!l&&r!l&&!r
000
scalar @{$meta_class_name . '::ISA';} and $meta_class_name->isa(__PACKAGE__)
!ll&&!rl&&r
000
MC/DC0%0/3
$meta_class_name eq __PACKAGE__ or scalar @{$meta_class_name . '::ISA';} and $meta_class_name->isa(__PACKAGE__)
$meta_class_name eq __PACKAGE__ scalar @{$meta_class_name . '::ISA';} $meta_class_name->isa(__PACKAGE__)
Truth table0%0/4
A or B and C
A= $meta_class_name eq __PACKAGE__B= scalar @{$meta_class_name . '::ISA';}C= $meta_class_name->isa(__PACKAGE__)
ABCresult
1XX1
0111
00X0
0100
204 $meta_class_name eq __PACKAGE__
205 or
206 # in newer Perl interpreters the ->isa() call can return true
207 # even if @ISA has been emptied (OS X) ???
208 0 (scalar(@{$meta_class_name . '::ISA'}) and $meta_class_name->isa(__PACKAGE__))
209 ) {
210 0 ▶ if (__PACKAGE__->get(class_name => $meta_class_name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (__PACKAGE__->get('class_name', $meta_class_name)) { } 0 0 0
211 0 warn "class $meta_class_name already exists when creating class meta for $class_name?!";
212 }
213 else {
214 0 __PACKAGE__->create(
215 __PACKAGE__->_construction_params_for_desc($desc)
216 );
217 }
218 }
219  
220 0 my $self = $class->_make_minimal_class_from_normalized_class_description($desc);
221 0 ▶ Carp::confess("Failed to define class $class_name!") unless $self;
Branch: 1 branch
BranchTrueFalseTotal
unless $self 0 0 0
222  
223 0 ▶ $self->_initialize_accessors_and_inheritance
Branch: 1 branch
BranchTrueFalseTotal
$self->_initialize_accessors_and_inheritance or Carp::confess("Failed to define class $class_name!") 0 0 0
224 or Carp::confess("Failed to define class $class_name!");
225  
226 0 ▶ $self->_inform_all_parent_classes_of_newly_loaded_subclass()
Branch: 1 branch
BranchTrueFalseTotal
$self->_inform_all_parent_classes_of_newly_loaded_subclass or Carp::confess("Failed to link to parent classes to complete definition of class $class_name!" . $class->error_message) 0 0 0
227 or Carp::confess(
228 "Failed to link to parent classes to complete definition of class $class_name!"
229 . $class->error_message
230 );
231  
232 0 $self->generated(0);
233  
234 0 $self->__signal_change__("create");
235  
236 0 return $self;
237 }
238  
239 0 ▶sub _preprocess_subclass_description {
Subroutine _preprocess_subclass_description: not called CC=4 SCAR=26.3
240 # allow a class to modify the description of any subclass before it instantiates
241 # this filtering allows a base class to specify policy, add meta properties, etc.
242 0 my ($self,$prev_desc) = @_;
243  
244 0 my $current_desc = $prev_desc;
245  
246 0 ▶ if (my $preprocessor = $self->subclass_description_preprocessor) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $preprocessor = $self->subclass_description_preprocessor) 0 0 0
247 # the preprocessor must me a method name in the class being adjusted
248 266 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
249 0 ▶ unless ($self->class_name->can($preprocessor)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->class_name->can($preprocessor)) 0 0 0
250 0 die "Class " . $self->class_name
251 . " specifies a pre-processor for subclass descriptions "
252 . $preprocessor . " which is not defined in the "
253 . $self->class_name . " package!";
254 }
255 0 $current_desc = $self->class_name->$preprocessor($current_desc);
256 0 $current_desc = $self->_normalize_class_description_impl(%$current_desc);
257 }
258  
259 # only call it on the direct parent classes, let recursion walk the tree
260 my @parent_class_names =
261 0 grep { $_->can('__meta__') }
262 $self->parent_class_names();
263  
264 0 for my $parent_class_name (@parent_class_names) {
265 0 my $parent_class = $parent_class_name->__meta__;
266 0 $current_desc = $parent_class->_preprocess_subclass_description($current_desc);
267 }
268  
269 0 return $current_desc;
270 }
271  
272 11966 ▶sub _construction_params_for_desc {
Subroutine _construction_params_for_desc: called CC=7 SCAR=26.6
273 11966 my $class = shift;
274 11966 my $desc = shift;
275  
276 11966 my $class_name = $desc->{class_name};
277 11966 my $meta_class_name = $desc->{meta_class_name};
278 11966 my @extended_metadata;
279 11966 ▶ if ($desc->{type_has}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($desc->{"type_has"}) 0 11966 11966
280 0 @extended_metadata = ( has => [ @{ $desc->{type_has} } ] );
281 }
282  
283 11966 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($meta_class_name eq __PACKAGE__) { } 6382 5584 11966
284 $meta_class_name eq __PACKAGE__
285 ) {
286 6382 ▶ if (@extended_metadata) {
Branch: 1 branch
BranchTrueFalseTotal
if (@extended_metadata) 0 6382 6382
287 0 die "Cannot extend class metadata of $class_name because it is a class involved in UR bootstrapping.";
288 }
289 6382 return();
290 }
291 else {
292 5584 ▶ if ($bootstrapping) {
Branch: 1 branch
BranchTrueFalseTotal
if ($UR::Object::Type::bootstrapping) { } 5584 0 5584
293 return (
294 5584 class_name => $meta_class_name,
295 is => __PACKAGE__,
296 @extended_metadata,
297 );
298 }
299 else {
300 0 my $parent_classes = $desc->{is};
301 0 my @meta_parent_classes = map { $_ . '::Type' } @$parent_classes;
302 0 for (@$parent_classes) {
303 0 __PACKAGE__->use_module_with_namespace_constraints($_);
304 0 eval {$_->class};
305 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
306 0 die "Error with parent class $_ when defining $class_name! $@";
307 }
308 }
309 return (
310 0 class_name => $meta_class_name,
311 is => \@meta_parent_classes,
312 @extended_metadata,
313 );
314 }
315 }
316  
317 }
318  
319  
320  
321 sub initialize_bootstrap_classes
322 266 ▶{
Subroutine initialize_bootstrap_classes: called CC=5 SCAR=23.1
Pod undocumented
323 # This is called once at the end of compiling the UR module set to handle
324 # classes which did incomplete initialization while bootstrapping.
325 # Until bootstrapping occurs is done,
326 266 my $class = shift;
327  
328 266 for my $class_meta (@partially_defined_classes) {
329 11966 ▶ unless ($class_meta->_inform_all_parent_classes_of_newly_loaded_subclass) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class_meta->_inform_all_parent_classes_of_newly_loaded_subclass) 0 11966 11966
330 0 my $class_name = $class_meta->{class_name};
331 0 Carp::confess (
332 "Failed to complete inheritance linkage definition of class $class_name!"
333 . $class_meta->error_message
334 );
335 }
336  
337 }
338 266 ▶ while (my $class_meta = shift @partially_defined_classes) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $class_meta = shift @UR::Object::Type::partially_defined_classes) 266 0 266
339 266 ▶ unless ($class_meta->_complete_class_meta_object_definitions()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class_meta->_complete_class_meta_object_definitions) 0 0 0
340 0 my $class_name = $class_meta->{class_name};
341 0 Carp::confess(
342 "Failed to complete definition of class $class_name!"
343 . $class_meta->error_message
344 );
345 }
346 }
347 0 $bootstrapping = 0;
348  
349 # It should be safe to set up callbacks now. register_callback() instead
350 # of create() so a subsequent rollback won't remove the observer.
351 0 UR::Observer->register_callback(
352 subject_class_name => 'UR::Object::Property',
353 subject_id => '',
354 aspect => '',
355 priority => 1,
356 note => '',
357 once => 0,
358 callback => \&UR::Object::Type::_property_change_callback,
359 );
360 }
361  
362 11966 ▶sub _normalize_class_description {
Subroutine _normalize_class_description: called CC=10 SCAR=32.6
363 11966 my $class = shift;
364 11966 my $desc = $class->_normalize_class_description_impl(@_);
365  
366 11966 ▶ $class->compose_roles($desc) unless $bootstrapping;
Branch: 1 branch
BranchTrueFalseTotal
unless $UR::Object::Type::bootstrapping 0 11966 11966
367  
368 11966 ▶ unless ($bootstrapping) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($UR::Object::Type::bootstrapping) 0 11966 11966
369 0 for my $parent_class_name (@{ $desc->{is} }) {
370 0 my $parent_class = $parent_class_name->__meta__;
371 0 $desc = $parent_class->_preprocess_subclass_description($desc);
372 }
373 }
374  
375 # we previously handled property meta extensions when normalizing the property
376 # now we merely save unrecognized things
377 # this is now done afterward so that parent classes can preprocess their subclasses descriptions before extending
378 # normalize the data behind the property descriptions
379 11966 my @property_names = keys %{$desc->{has}};
380 11966 for my $property_name (@property_names) {
381 48408 ▶ Carp::croak("Invalid property name in class ".$desc->{class_name}.": '$property_name'")
Branch: 1 branch
BranchTrueFalseTotal
unless UR::Util::is_valid_property_name($property_name) 0 48408 48408
382 unless UR::Util::is_valid_property_name($property_name);
383  
384 48408 my $pdesc = $desc->{has}->{$property_name};
385 48408 my $unknown_ma = delete $pdesc->{unrecognized_meta_attributes};
386 48408 ▶ next unless $unknown_ma;
Branch: 1 branch
BranchTrueFalseTotal
unless $unknown_ma 48408 0 48408
387 0 for my $name (keys %$unknown_ma) {
388 0 ▶ if (exists $desc->{attributes_have}->{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $desc->{"attributes_have"}{$name}) 0 0 0
389 0 $pdesc->{$name} = delete $unknown_ma->{$name};
390 }
391 }
392 0 ▶ if (%$unknown_ma) {
Branch: 1 branch
BranchTrueFalseTotal
if (%$unknown_ma) 0 0 0
393 0 my $class_name = $desc->{class_name};
394 0 my @unknown_ma = sort keys %$unknown_ma;
395 0 Carp::confess("unknown meta-attributes present for $class_name $property_name: @unknown_ma\n");
396 }
397 }
398  
399 11966 return $desc;
400 }
401  
402 11966 ▶sub _canonicalize_class_params {
Subroutine _canonicalize_class_params: called CC=4 SCAR=14.0
403 11966 my($params, $mappings) = @_;
404  
405 11966 my %canon_params;
406  
407 11966 for my $mapping ( @$mappings ) {
408 406844 my ($primary_field_name, @alternate_field_names) = @$mapping;
409 406844 my @all_fields = ($primary_field_name, @alternate_field_names);
410 406844 my @values = grep { defined($_) } delete @$params{@all_fields};
411 406844 ▶ if (@values > 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@values > 1) { } 0 406844 406844
elsif (@values == 1) { } 19944 386900 406844
412 0 Carp::confess(
413 "Multiple values in for field "
414 . join("/", @all_fields)
415 );
416 }
417 elsif (@values == 1) {
418 19944 $canon_params{$primary_field_name} = $values[0];
419 }
420 }
421  
422 11966 return %canon_params;
423 }
424  
425 143 our @CLASS_DESCRIPTION_KEY_MAPPINGS_COMMON_TO_CLASSES_AND_ROLES = (
426 [ roles => qw//],
427 [ is_abstract => qw/abstract/],
428 [ is_final => qw/final/],
429 [ is_singleton => qw//],
430 [ is_transactional => qw//],
431 [ id_by => qw/id_properties/],
432 [ has => qw/properties/],
433 [ type_has => qw//],
434 [ attributes_have => qw//],
435 [ er_role => qw/er_type/],
436 [ doc => qw/description/],
437 [ relationships => qw//],
438 [ constraints => qw/unique_constraints/],
439 [ namespace => qw//],
440 [ schema_name => qw//],
441 [ data_source_id => qw/data_source instance/],
442 [ select_hint => qw/query_hint/],
443 [ join_hint => qw//],
444 [ subclassify_by => qw/sub_classification_property_name/],
445 [ sub_classification_meta_class_name => qw//],
446 [ sub_classification_method_name => qw//],
447 [ first_sub_classification_method_name => qw//],
448 [ composite_id_separator => qw//],
449 [ generate => qw//],
450 [ generated => qw//],
451 [ subclass_description_preprocessor => qw//],
452 [ id_generator => qw/id_sequence_generator_name/],
453 [ subclassify_by_version => qw//],
454 [ meta_class_name => qw//],
455 [ valid_signals => qw//],
456 );
457  
458 143 my @CLASS_DESCRIPTION_KEY_MAPPINGS = (
459 @CLASS_DESCRIPTION_KEY_MAPPINGS_COMMON_TO_CLASSES_AND_ROLES,
460 [ class_name => qw//],
461 [ type_name => qw/english_name/],
462 [ is => qw/inheritance extends isa is_a/],
463 [ table_name => qw/sql dsmap/],
464 );
465  
466 11966 ▶sub _normalize_class_description_impl {
Subroutine _normalize_class_description_impl: called CC=52 SCAR=63.6
467 11966 my $class = shift;
468 11966 my %old_class = @_;
469  
470 11966 ▶ if (exists $old_class{extra}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $old_class{"extra"}) 0 11966 11966
471 0 %old_class = (%{delete $old_class{extra}}, %old_class);
472 }
473  
474 11966 my $class_name = delete $old_class{class_name};
475  
476 my %new_class = (
477 class_name => $class_name,
478 is_singleton => $UR::Object::Type::defaults{'is_singleton'},
479 is_final => $UR::Object::Type::defaults{'is_final'},
480 11966 is_abstract => $UR::Object::Type::defaults{'is_abstract'},
481 _canonicalize_class_params(\%old_class, \@CLASS_DESCRIPTION_KEY_MAPPINGS),
482 );
483  
484 11966 ▶ if (my $pp = $new_class{subclass_description_preprocessor}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pp = $new_class{"subclass_description_preprocessor"}) 0 11966 11966
485 0 ▶ if (!ref($pp)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $pp) { } 0 0 0
elsif (ref $pp ne 'CODE') { } 0 0 0
486 0 ▶ unless ($pp =~ /::/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pp =~ /::/) { } 0 0 0
487 # a method name, not fully qualified
488 $new_class{subclass_description_preprocessor} =
489 $new_class{class_name}
490 . '::'
491 0 . $new_class{subclass_description_preprocessor};
492 } else {
493 0 $new_class{subclass_description_preprocessor} = $pp;
494 }
495 }
496 elsif (ref($pp) ne 'CODE') {
497 0 die "unexpected " . ref($pp) . " reference for subclass_description_preprocessor for $class_name!";
498 }
499 }
500  
501 11966 ▶ unless ($new_class{er_role}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($new_class{"er_role"}) 11966 0 11966
502 11966 $new_class{er_role} = $UR::Object::Type::defaults{'er_role'};
503 }
504  
505 11966 my @crap = qw/source/;
506 11966 delete @old_class{@crap};
507  
508 11966 ▶ if ($class_name =~ /^(.*?)::/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class_name =~ /^(.*?)::/) { } 11700 266 11966
509 11700 $new_class{namespace} = $1;
510 }
511 else {
512 266 $new_class{namespace} = $new_class{class_name};
513 }
514  
515 11966 ▶ if (not exists $new_class{is_transactional}
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $new_class{"is_transactional"} or $UR::Object::Type::meta_classes{$class_name}) 9839 2127 11966
Condition100%3/3
exists $new_class{"is_transactional"} or $UR::Object::Type::meta_classes{$class_name}
l!l&&r!l&&!r
13297989839
MC/DC100%2/2
exists $new_class{"is_transactional"} or $UR::Object::Type::meta_classes{$class_name}
exists $new_class{"is_transactional"} $UR::Object::Type::meta_classes{$class_name}
Truth table100%3/3
A or B
A= exists $new_class{"is_transactional"}B= $UR::Object::Type::meta_classes{$class_name}
ABresult
1X1
011
000
516 and not $meta_classes{$class_name}
517 ) {
518 9839 $new_class{is_transactional} = $UR::Object::Type::defaults{'is_transactional'};
519 }
520  
521 11966 ▶ unless ($new_class{is}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($new_class{"is"}) 2394 9572 11966
522 266 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
523 266 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
524 2394 ▶ if (my @isa = @{ $class_name . "::ISA" }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@isa) = @{$class_name . '::ISA';}) 532 1862 2394
525 532 $new_class{is} = \@isa;
526 }
527 }
528  
529 11966 ▶ unless ($new_class{is}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($new_class{"is"}) 1862 10104 11966
530 1862 ▶ if ($new_class{table_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_class{'table_name'}) { } 0 1862 1862
531 0 $new_class{is} = ['UR::Entity']
532 }
533 else {
534 1862 $new_class{is} = ['UR::Object']
535 }
536 }
537  
538 11966 ▶ unless ($new_class{'doc'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($new_class{"doc"}) 10902 1064 11966
539 10902 $new_class{'doc'} = undef;
540 }
541  
542 11966 foreach my $key ( qw(valid_signals roles) ) {
543 23932 ▶ unless (UR::Util::ensure_arrayref(\%new_class, $key)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UR::Util::ensure_arrayref(\%new_class, $key)) 0 23932 23932
544 0 Carp::croak("The '$key' metadata for class $class_name must be an arrayref");
545 }
546 }
547  
548 # Later code expects these to be listrefs
549 11966 for my $field (qw/is id_by has relationships constraints/) {
550 59830 _massage_field_into_arrayref(\%new_class, $field);
551 }
552  
553  
554 # These may have been found and moved over. Restore.
555 11966 $old_class{has} = delete $new_class{has};
556 11966 $old_class{attributes_have} = delete $new_class{attributes_have};
557  
558 # Install structures to track fully formatted property data.
559 11966 my $instance_properties = $new_class{has} = {};
560 11966 my $meta_properties = $new_class{attributes_have} = {};
561  
562 # The id might be a single value, or not specified at all.
563 11966 my $id_properties;
564 11966 ▶ if (not exists $new_class{id_by}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not exists $new_class{'id_by'}) { } 0 11966 11966
elsif (not ref $new_class{'id_by'} or ref $new_class{'id_by'} ne 'ARRAY') { } 0 11966 11966
565 0 ▶ if ($new_class{is}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_class{'is'}) { } 0 0 0
566 0 $id_properties = $new_class{id_by} = [];
567 }
568 else {
569 0 $id_properties = $new_class{id_by} = [ id => { is_optional => 0 } ];
570 }
571 }
572 ▶ elsif ( (not ref($new_class{id_by})) or (ref($new_class{id_by}) ne 'ARRAY') ) {
Condition33%1/3
not ref $new_class{"id_by"} or ref $new_class{"id_by"} ne "ARRAY"
l!l&&r!l&&!r
0011966
MC/DC0%0/2
not ref $new_class{"id_by"} or ref $new_class{"id_by"} ne "ARRAY"
not ref $new_class{"id_by"} ref $new_class{"id_by"} ne "ARRAY"
Truth table33%1/3
not(A) or B
A= not ref $new_class{"id_by"}B= ref $new_class{"id_by"} ne "ARRAY"
ABresult
1X1
011
000
573 0 $id_properties = $new_class{id_by} = [ $new_class{id_by} ];
574 }
575 else {
576 11966 $id_properties = $new_class{id_by};
577 }
578  
579 11966 _normalize_id_property_data(\%old_class, \%new_class);
580  
581 11966 ▶ if (@$id_properties > 1
Branch: 1 branch
BranchTrueFalseTotal
if (@$id_properties > 1 and grep {$_ eq "id";} @$id_properties) 0 11966 11966
Condition66%2/3
@$id_properties > 1 and grep {$_ eq "id";} @$id_properties
!ll&&!rl&&r
1063613300
MC/DC0%0/2
@$id_properties > 1 and grep {$_ eq "id";} @$id_properties
@$id_properties > 1 grep {$_ eq "id";} @$id_properties
Truth table66%2/3
A and B
A= @$id_properties > 1B= grep {$_ eq "id";} @$id_properties
ABresult
0X0
100
111
582 3458 and grep {$_ eq 'id'} @$id_properties)
583 {
584 Carp::croak("Cannot initialize class $class_name: "
585 . "Cannot have an ID property named 'id' when the class has multiple ID properties ("
586 0 . join(', ', map { "'$_'" } @$id_properties)
587 . ")");
588 }
589  
590 11966 _process_class_definition_property_keys(\%old_class, \%new_class);
591  
592 # NOT ENABLED YET
593 11966 if (0) {
594 # done processing direct properties of this process
595 # extend %$instance_properties with properties of the parent classes
596 my @parent_class_names = @{ $new_class{is} };
597 for my $parent_class_name (@parent_class_names) {
598 my $parent_class_meta = $parent_class_name->__meta__;
599 die "no meta for $parent_class_name while initializing $class_name?" unless $parent_class_meta;
600 my $parent_normalized_properties = $parent_class_meta->{has};
601 for my $parent_property_name (keys %$parent_normalized_properties) {
602 my $parent_property_data = $parent_normalized_properties->{$parent_property_name};
603 my $inherited_copy = $instance_properties->{$parent_property_name};
604 unless ($inherited_copy) {
605 $inherited_copy = UR::Util::deep_copy($parent_property_data);
606 }
607 $inherited_copy->{class_name} = $class_name;
608 my $override = $inherited_copy->{overrides_class_names} ||= [];
609 push @$override, $parent_property_data->{class_name};
610 }
611 }
612 }
613  
614 11966 ▶ if (($new_class{data_source_id} and not ref($new_class{data_source_id})) and not $new_class{schema_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_class{"data_source_id"} and not ref $new_class{"data_source_id"} and not $new_class{"schema_name"}) 0 11966 11966
Condition33%2/6
$new_class{"data_source_id"} and not ref $new_class{"data_source_id"} and not $new_class{"schema_name"}
!ll&&!rl&&r
1196600
$new_class{"data_source_id"} and not ref $new_class{"data_source_id"}
!ll&&!rl&&r
1196600
MC/DC0%0/3
$new_class{"data_source_id"} and not ref $new_class{"data_source_id"} and not $new_class{"schema_name"}
$new_class{"data_source_id"} not ref $new_class{"data_source_id"} not $new_class{"schema_name"}
Truth table25%1/4
A and not(B) and not(C)
A= $new_class{"data_source_id"}B= not ref $new_class{"data_source_id"}C= not $new_class{"schema_name"}
ABCresult
0XX0
10X0
1100
1111
615 0 my $s = $new_class{data_source_id};
616 0 $s =~ s/^.*::DataSource:://;
617 0 $new_class{schema_name} = $s;
618 }
619  
620 11966 ▶ if (%old_class) {
Branch: 1 branch
BranchTrueFalseTotal
if (%old_class) 0 11966 11966
621 # this should have all been deleted above
622 # we actually process it later, since these may be related to parent classes extending
623 # the class definition
624 0 $new_class{extra} = \%old_class;
625 };
626  
627 # ensure parent classes are loaded
628 11966 ▶ unless ($bootstrapping) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($UR::Object::Type::bootstrapping) 0 11966 11966
629 0 ▶ my @base_classes = map { ref($_) ? @$_ : $_ } $new_class{is};
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 0 0
630 0 for my $parent_class_name (@base_classes) {
631 # ensure the parent classes are fully processed
632 266 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
633 0 ▶ unless ($parent_class_name->can("__meta__")) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($parent_class_name->can("__meta__")) 0 0 0
634 0 __PACKAGE__->use_module_with_namespace_constraints($parent_class_name);
635 0 ▶ Carp::croak("Class $class_name cannot initialize because of errors using parent class $parent_class_name: $@") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
636 }
637 0 ▶ unless ($parent_class_name->can("__meta__")) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($parent_class_name->can("__meta__")) 0 0 0
638 0 ▶ if ($ENV{'HARNESS_ACTIVE'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"HARNESS_ACTIVE"}) 0 0 0
639 0 Carp::confess("Class $class_name cannot initialize because of errors using parent class $parent_class_name. Failed to find static method '__meta__' on $parent_class_name. Does class $parent_class_name exist, and is it loaded?\n The entire list of base classes was ".join(', ', @base_classes));
640 }
641 0 Carp::croak("Class $class_name cannot initialize because of errors using parent class $parent_class_name. Failed to find static method '__meta__' on $parent_class_name. Does class $parent_class_name exist, and is it loaded?");
642 }
643 0 my $parent_class = $parent_class_name->__meta__;
644 0 ▶ unless ($parent_class) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($parent_class) 0 0 0
645 0 Carp::carp("No class metadata object for $parent_class_name");
646 0 next;
647 }
648  
649 # the the parent classes indicate version, if needed
650 0 ▶ if ($parent_class->{'subclassify_by_version'} and not $parent_class_name =~ /::Ghost/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent_class->{"subclassify_by_version"} and not $parent_class_name =~ /::Ghost/) 0 0 0
Condition0%0/3
$parent_class->{"subclassify_by_version"} and not $parent_class_name =~ /::Ghost/
!ll&&!rl&&r
000
MC/DC0%0/2
$parent_class->{"subclassify_by_version"} and not $parent_class_name =~ /::Ghost/
$parent_class->{"subclassify_by_version"} not $parent_class_name =~ /::Ghost/
Truth table0%0/3
A and not(B)
A= $parent_class->{"subclassify_by_version"}B= not $parent_class_name =~ /::Ghost/
ABresult
0X0
100
111
651 0 ▶ unless ($class_name =~ /^${parent_class_name}::V\d+/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class_name =~ /^$parent_class_name::V\d+/) 0 0 0
652 0 my $ns = $parent_class_name;
653 0 $ns =~ s/::.*//;
654 0 my $version;
655 0 ▶ if ($ns and $ns->can("component_version")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ns and $ns->can("component_version")) 0 0 0
Condition0%0/3
$ns and $ns->can("component_version")
!ll&&!rl&&r
000
MC/DC0%0/2
$ns and $ns->can("component_version")
$ns $ns->can("component_version")
Truth table0%0/3
A and B
A= $nsB= $ns->can("component_version")
ABresult
0X0
100
111
656 0 $version = $ns->component_version($class);
657 }
658 0 ▶ unless ($version) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($version) 0 0 0
659 0 $version = '1';
660 }
661 0 $parent_class_name = $parent_class_name . '::V' . $version;
662 0 eval "use $parent_class_name";
663 0 ▶ Carp::confess("Error using versioned module $parent_class_name!:\n$@") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
664 0 redo;
665 }
666 }
667 }
668 0 $new_class{is} = \@base_classes;
669 }
670  
671 # allow parent classes to adjust the description in systematic ways
672 11966 my @additional_property_meta_attributes;
673 11966 ▶ unless ($bootstrapping) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($UR::Object::Type::bootstrapping) 0 11966 11966
674 0 for my $parent_class_name (@{ $new_class{is} }) {
675 0 my $parent_class = $parent_class_name->__meta__;
676 0 ▶ if (my $parent_meta_properties = $parent_class->{attributes_have}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $parent_meta_properties = $parent_class->{"attributes_have"}) 0 0 0
677 0 push @additional_property_meta_attributes, %$parent_meta_properties;
678 }
679 }
680 }
681  
682 11966 __PACKAGE__->_normalize_property_descriptions_during_normalize_class_description(\%new_class);
683  
684 11966 ▶ unless ($bootstrapping) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($UR::Object::Type::bootstrapping) 0 11966 11966
685 0 %$meta_properties = (%$meta_properties, @additional_property_meta_attributes);
686  
687 # Inheriting from an abstract class that subclasses with a subclassify_by means that
688 # this class' property named by that subclassify_by is actually a constant equal to this
689 # class' class name
690 PARENT_CLASS:
691 0 foreach my $parent_class_name ( @{ $new_class{'is'} }) {
692 0 my $parent_class_meta = $parent_class_name->__meta__();
693 0 foreach my $ancestor_class_meta ( $parent_class_meta->all_class_metas ) {
694 0 ▶ if (my $subclassify_by = $ancestor_class_meta->subclassify_by) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $subclassify_by = $ancestor_class_meta->subclassify_by) 0 0 0
695 0 ▶ if (not $instance_properties->{$subclassify_by}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($instance_properties->{$subclassify_by}) 0 0 0
696 0 my %old_property = (
697 property_name => $subclassify_by,
698 default_value => $class_name,
699 is_constant => 1,
700 is_classwide => 1,
701 is_specified_in_module_header => 0,
702 column_name => '',
703 implied_by => $parent_class_meta->class_name . '::subclassify_by',
704 );
705 0 my %new_property = $class->_normalize_property_description1($subclassify_by, \%old_property, \%new_class);
706 0 my %new_property2 = $class->_normalize_property_description2(\%new_property, \%new_class);
707 0 $instance_properties->{$subclassify_by} = \%new_property2;
708 0 last PARENT_CLASS;
709 }
710 }
711 }
712 }
713 }
714  
715 11966 my $meta_class_name = __PACKAGE__->_resolve_meta_class_name_for_class_name($class_name);
716 11966 ▶ $new_class{meta_class_name} ||= $meta_class_name;
Condition33%1/3
$new_class{"meta_class_name"} ||= $meta_class_name
l!l&&r!l&&!r
0119660
MC/DC0%0/2
$new_class{"meta_class_name"} ||= $meta_class_name
$new_class{"meta_class_name"} $meta_class_name
Truth table33%1/3
A ||= B
A= $new_class{"meta_class_name"}B= $meta_class_name
ABresult
1X1
011
000
717 11966 return \%new_class;
718 }
719  
720 # Transform the id properties into a list of raw ids,
721 # and move the property definitions into "id_implied"
722 # where present so they can be processed below.
723 11966 ▶sub _normalize_id_property_data {
Subroutine _normalize_id_property_data: called CC=7 SCAR=20.2
724 11966 my($old_class_desc, $new_class_desc) = @_;
725  
726 11966 my $id_properties = $new_class_desc->{id_by};
727 11966 my $property_rank = 0;
728 11966 my @replacement;
729 11966 my $pos = 0;
730  
731 11966 ▶ for(my $n = 0; $n < @$id_properties; $n++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n < @$id_properties) 3990 11966 15956
732 3990 my $name = $id_properties->[$n];
733  
734 3990 my $data = $id_properties->[$n+1];
735 3990 ▶ if (ref($data)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data) { } 2394 1596 3990
736 2394 ▶ $old_class_desc->{id_implied}->{$name} ||= $data;
Condition33%1/3
$old_class_desc->{"id_implied"}{$name} ||= $data
l!l&&r!l&&!r
023940
MC/DC0%0/2
$old_class_desc->{"id_implied"}{$name} ||= $data
$old_class_desc->{"id_implied"}{$name} $data
Truth table33%1/3
A ||= B
A= $old_class_desc->{"id_implied"}{$name}B= $data
ABresult
1X1
011
000
737 2394 ▶ if (my $obj_ids = $data->{id_by}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $obj_ids = $data->{'id_by'}) { } 0 2394 2394
738 0 ▶ push @replacement, (ref($obj_ids) ? @$obj_ids : ($obj_ids));
Branch: 1 branch
BranchTrueFalseTotal
ref $obj_ids ? : 0 0 0
739 }
740 else {
741 2394 push @replacement, $name;
742 }
743 2394 $n++;
744 }
745 else {
746 1596 ▶ $old_class_desc->{id_implied}->{$name} ||= {};
Condition50%1/2
$old_class_desc->{"id_implied"}{$name} ||= {}
l!l
01596
MC/DC0%0/1
$old_class_desc->{"id_implied"}{$name} ||= {}
$old_class_desc->{"id_implied"}{$name}
Truth table50%1/2
A
A= $old_class_desc->{"id_implied"}{$name}
Aresult
11
00
747 1596 push @replacement, $name;
748 }
749 3990 $old_class_desc->{id_implied}->{$name}->{'position_in_module_header'} = $pos++;
750 }
751 11966 @$id_properties = @replacement;
752 }
753  
754 # Given several different kinds of input, convert it into an arrayref
755 59830 ▶sub _massage_field_into_arrayref {
Subroutine _massage_field_into_arrayref: called CC=5 SCAR=17.3
756 59830 my($class_desc, $field_name) = @_;
757  
758 59830 my $value = $class_desc->{$field_name};
759 59830 my $reftype = ref $value;
760 59830 ▶ if (! exists $class_desc->{$field_name}) {
Branch: 4 branches
BranchTrueFalseTotal
if (not exists $class_desc->{$field_name}) { } 43609 16221 59830
elsif (not $reftype) { } 5850 10371 16221
elsif ($reftype eq 'HASH') { } 0 10371 10371
elsif ($reftype ne 'ARRAY') { } 0 10371 10371
761 43609 $class_desc->{$field_name} = [];
762  
763 } elsif (! $reftype) {
764 # It's a plain string, wrap it in an arrayref
765 5850 $class_desc->{$field_name} = [ $value ];
766  
767 } elsif ($reftype eq 'HASH') {
768 # Later code expects it to be a listref - convert it
769 0 $class_desc->{$field_name} = [ %$value ];
770  
771 } elsif ($reftype ne 'ARRAY') {
772 0 my $class_name = $class_desc->{class_name};
773 0 Carp::croak "$class_name cannot initialize because its $field_name section is not a string, arrayref or hashref";
774  
775 }
776 }
777  
778 11966 ▶sub _normalize_property_descriptions_during_normalize_class_description {
Subroutine _normalize_property_descriptions_during_normalize_class_description: called CC=13 SCAR=32.0
779 11966 my($class, $new_class) = @_;
780  
781 11966 my $instance_properties = $new_class->{has};
782  
783 # normalize the data behind the property descriptions
784 11966 my @property_names = keys %$instance_properties;
785 11966 for my $property_name (@property_names) {
786 48408 my %old_property = %{ $instance_properties->{$property_name} };
787 48408 my %new_property = $class->_normalize_property_description1($property_name, \%old_property, $new_class);
788 48408 %new_property = $class->_normalize_property_description2(\%new_property, $new_class);
789 48408 $instance_properties->{$property_name} = \%new_property;
790 }
791  
792 # Find 'via' properties where the to is '-filter' and rewrite them to
793 # copy some attributes from the source property
794 # This feels like a hack, but it makes other parts of the system easier by
795 # not having to deal with -filter
796 11966 foreach my $property_name ( @property_names ) {
797 48408 my $property_data = $instance_properties->{$property_name};
798 48408 ▶ if ($property_data->{'to'} && $property_data->{'to'} eq '-filter') {
Branch: 1 branch
BranchTrueFalseTotal
if ($property_data->{"to"} and $property_data->{"to"} eq "-filter") 0 48408 48408
Condition66%2/3
$property_data->{"to"} and $property_data->{"to"} eq "-filter"
!ll&&!rl&&r
38300101080
MC/DC0%0/2
$property_data->{"to"} and $property_data->{"to"} eq "-filter"
$property_data->{"to"} $property_data->{"to"} eq "-filter"
Truth table66%2/3
A and B
A= $property_data->{"to"}B= $property_data->{"to"} eq "-filter"
ABresult
0X0
100
111
799 0 my $via = $property_data->{'via'};
800 0 my $via_property_data = $instance_properties->{$via};
801 0 ▶ unless ($via_property_data) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($via_property_data) 0 0 0
802 0 my $class_name = $new_class->{class_name};
803 0 Carp::croak "Cannot initialize class $class_name: Property '$property_name' filters '$via', but there is no property '$via'.";
804 }
805  
806 0 $property_data->{'data_type'} = $via_property_data->{'data_type'};
807 0 $property_data->{'reverse_as'} = $via_property_data->{'reverse_as'};
808 0 ▶ if ($via_property_data->{'where'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($via_property_data->{"where"}) 0 0 0
809 0 unshift @{$property_data->{'where'}}, @{$via_property_data->{'where'}};
810 }
811 }
812 }
813  
814 # Catch a mistake in the class definition where a property is 'via'
815 # something, and its 'to' is the same as the via's reverse_as. This
816 # ends up being a circular definition and generates junk SQL
817 11966 foreach my $property_name ( @property_names ) {
818 48408 my $property_data = $instance_properties->{$property_name};
819 48408 my $via = $property_data->{'via'};
820 48408 my $to = $property_data->{'to'};
821 48408 ▶ if (defined($via) and defined($to)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $via and defined $to) 10108 38300 48408
Condition66%2/3
defined $via and defined $to
!ll&&!rl&&r
38300010108
MC/DC50%1/2
defined $via and defined $to
defined $via defined $to
Truth table66%2/3
A and B
A= defined $viaB= defined $to
ABresult
0X0
100
111
822 10108 my $via_property_data = $instance_properties->{$via};
823 10108 ▶ next unless ($via_property_data and $via_property_data->{'reverse_as'});
Branch: 1 branch
BranchTrueFalseTotal
unless $via_property_data and $via_property_data->{"reverse_as"} 8246 1862 10108
Condition66%2/3
$via_property_data and $via_property_data->{"reverse_as"}
!ll&&!rl&&r
082461862
MC/DC50%1/2
$via_property_data and $via_property_data->{"reverse_as"}
$via_property_data $via_property_data->{"reverse_as"}
Truth table66%2/3
A and B
A= $via_property_dataB= $via_property_data->{"reverse_as"}
ABresult
0X0
100
111
824 1862 ▶ if ($via_property_data->{'reverse_as'} eq $to) {
Branch: 1 branch
BranchTrueFalseTotal
if ($via_property_data->{"reverse_as"} eq $to) 0 1862 1862
825 0 my $class_name = $new_class->{class_name};
826 0 Carp::croak("Cannot initialize class $class_name: Property '$property_name' defines "
827 . "an incompatible relationship. Its 'to' is the same as reverse_as for property '$via'");
828 }
829 }
830 }
831 }
832  
833 11966 ▶sub _process_class_definition_property_keys {
Subroutine _process_class_definition_property_keys: called CC=45 SCAR=39.3
834 11966 my($old_class, $new_class) = @_;
835  
836 11966 my($class_name, $instance_properties, $meta_properties) = @$new_class{'class_name', 'has','attributes_have'};
837 11966 ▶ $class_name ||= $new_class->{role_name}; # This is used by role construction, too
Condition33%1/3
$class_name ||= $new_class->{"role_name"}
l!l&&r!l&&!r
1196600
MC/DC0%0/2
$class_name ||= $new_class->{"role_name"}
$class_name $new_class->{"role_name"}
Truth table33%1/3
A ||= B
A= $class_nameB= $new_class->{"role_name"}
ABresult
1X1
011
000
838  
839 # Flatten and format the property list(s) in the class description.
840 # NOTE: we normalize the details at the end of normalizing the class description.
841 11966 my @keys = _class_definition_property_keys_in_processing_order($old_class);
842 11966 foreach my $key ( @keys ) {
843 # parse the key to see if we're looking at instance or meta attributes,
844 # and take the extra words as additional attribute meta-data.
845 26326 my @added_property_meta;
846 my $properties;
847 26326 ▶ if ($key =~ /has/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($key =~ /has/) { } 12498 13828 26326
elsif ($key =~ /attributes_have/) { } 11966 1862 13828
elsif ($key eq 'id_implied') { } 1862 0 1862
848 @added_property_meta =
849 12498 grep { $_ ne 'has' } split(/[_-]/,$key);
850 12498 $properties = $instance_properties;
851 }
852 elsif ($key =~ /attributes_have/) {
853 @added_property_meta =
854 11966 ▶ grep { $_ ne 'attributes' and $_ ne 'have' } split(/[_-]/,$key);
Condition66%2/3
$_ ne 'attributes' && $_ ne 'have'
!ll&&!rl&&r
11966119660
MC/DC0%0/2
$_ ne 'attributes' && $_ ne 'have'
$_ ne 'attributes' $_ ne 'have'
Truth table66%2/3
A && B
A= $_ ne 'attributes'B= $_ ne 'have'
ABresult
0X0
100
111
855 11966 $properties = $meta_properties;
856 }
857 elsif ($key eq 'id_implied') {
858 # these are additions to the regular "has" list from complex identity properties
859 1862 $properties = $instance_properties;
860 }
861 else {
862 0 die "Odd key $key?";
863 }
864 26326 @added_property_meta = map { 'is_' . $_ => 1 } @added_property_meta;
865  
866 # the property data can be a string, array, or hash as they come in
867 # convert string, hash and () into an array
868 26326 my $property_data = delete $old_class->{$key};
869  
870 26326 my @tmp;
871 26326 ▶ if (!ref($property_data)) {
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $property_data) { } 11966 14360 26326
elsif (ref $property_data eq 'HASH') { } 1862 12498 14360
elsif (ref $property_data eq 'ARRAY') { } 12498 0 12498
872 11966 ▶ if (defined($property_data)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $property_data) { } 0 11966 11966
873 0 @tmp = split(/\s+/, $property_data);
874 }
875 else {
876 11966 @tmp = ();
877 }
878 }
879 elsif (ref($property_data) eq 'HASH') {
880 @tmp = map {
881 1862 ($_ => $property_data->{$_})
882 } sort keys %$property_data;
883 }
884 elsif (ref($property_data) eq 'ARRAY') {
885 12498 @tmp = @$property_data;
886 }
887 else {
888 0 die "Unrecognized data $property_data appearing as property list!";
889 }
890  
891 # process the array of property specs
892 26326 my $pos = 0;
893 26326 ▶ while (my $name = shift @tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $name = shift @tmp) 51334 26326 77660
894 51334 my $params;
895 51334 ▶ if (ref($tmp[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $tmp[0]) { } 50802 532 51334
896 50802 $params = shift @tmp;
897 50802 ▶ unless (ref($params) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $params eq "HASH") 0 50802 50802
898 0 my $seen_type = ref($params);
899 0 Carp::confess("class $class_name property $name has a $seen_type reference instead of a hashref describing its meta-attributes!");
900 }
901 50802 ▶ %$params = (@added_property_meta, %$params) if @added_property_meta;
Branch: 1 branch
BranchTrueFalseTotal
if @added_property_meta 16226 34576 50802
902 }
903 else {
904 532 $params = { @added_property_meta };
905 }
906  
907 51334 ▶ unless (exists $params->{'position_in_module_header'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $params->{"position_in_module_header"}) 47344 3990 51334
908 47344 $params->{'position_in_module_header'} = $pos++;
909 }
910 51334 ▶ unless (exists $params->{is_specified_in_module_header}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $params->{"is_specified_in_module_header"}) 48940 2394 51334
911 48940 $params->{is_specified_in_module_header} = $class_name . '::' . $key;
912 }
913  
914 # Indirect properties can mention the same property name more than once. To
915 # avoid stomping over existing property data with this other property data,
916 # merge the new info into the existing hash. Otherwise, the new property name
917 # gets an empty hash of info
918 51334 ▶ if ($properties->{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($properties->{$name}) { } 2926 48408 51334
919 # this property already exists, but is also implied by some other property which added it to the end of the listed
920 # extend the existing definition
921 2926 foreach my $key ( keys %$params ) {
922 9576 ▶ next if ($key eq 'is_specified_in_module_header' || $key eq 'position_in_module_header');
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "is_specified_in_module_header" or $key eq "position_in_module_header" 5852 3724 9576
Condition100%3/3
$key eq "is_specified_in_module_header" or $key eq "position_in_module_header"
l!l&&r!l&&!r
292629263724
MC/DC100%2/2
$key eq "is_specified_in_module_header" or $key eq "position_in_module_header"
$key eq "is_specified_in_module_header" $key eq "position_in_module_header"
Truth table100%3/3
A or B
A= $key eq "is_specified_in_module_header"B= $key eq "position_in_module_header"
ABresult
1X1
011
000
923 # once a property gets set to is_optional => 0, it stays there, even if it's later set to 1
924 next if ($key eq 'is_optional'
925 and
926 exists($properties->{$name}->{'is_optional'})
927 and
928 defined($properties->{$name}->{'is_optional'})
929 and
930 3724 ▶ $properties->{$name}->{'is_optional'} == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "is_optional" and exists $properties->{$name}{"is_optional"} and defined $properties->{$name}{"is_optional"} and $properties->{$name}{"is_optional"} == 0 0 3724 3724
Condition77%7/9
$key eq "is_optional" and exists $properties->{$name}{"is_optional"} and defined $properties->{$name}{"is_optional"} and $properties->{$name}{"is_optional"} == 0
!ll&&!rl&&r
34582660
$key eq "is_optional" and exists $properties->{$name}{"is_optional"} and defined $properties->{$name}{"is_optional"}
!ll&&!rl&&r
34580266
$key eq "is_optional" and exists $properties->{$name}{"is_optional"}
!ll&&!rl&&r
2926532266
MC/DC0%0/4
$key eq "is_optional" and exists $properties->{$name}{"is_optional"} and defined $properties->{$name}{"is_optional"} and $properties->{$name}{"is_optional"} == 0
$key eq "is_optional" exists $properties->{$name}{"is_optional"} defined $properties->{$name}{"is_optional"} $properties->{$name}{"is_optional"} == 0
Truth table60%3/5
A and B and C and D
A= $key eq "is_optional"B= exists $properties->{$name}{"is_optional"}C= defined $properties->{$name}{"is_optional"}D= $properties->{$name}{"is_optional"} == 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
931 3724 $properties->{$name}->{$key} = $params->{$key};
932 }
933 2926 $params = $properties->{$name};
934 } else {
935 48408 $properties->{$name} = $params;
936 }
937  
938 # a single calculate_from can be a simple string, convert to a listref
939 51334 ▶ if (my $calculate_from = $params->{'calculate_from'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $calculate_from = $params->{"calculate_from"}) 266 51068 51334
940 266 ▶ $params->{'calculate_from'} = [ $calculate_from ] unless (ref($calculate_from) eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $calculate_from eq "ARRAY" 0 266 266
941 }
942  
943 51334 ▶ if (my $id_by = $params->{id_by}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $id_by = $params->{"id_by"}) 2128 49206 51334
944 2128 ▶ $id_by = [ $id_by ] unless ref($id_by) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $id_by eq "ARRAY" 2128 0 2128
945 2128 my @id_by_names;
946 2128 ▶ while (@$id_by) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$id_by) 2128 2128 4256
947 2128 my $id_name = shift @$id_by;
948 2128 my $params2;
949 2128 ▶ if (ref($id_by->[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $id_by->[0]) { } 0 2128 2128
950 0 $params2 = shift @$id_by;
951 }
952 else {
953 2128 $params2 = {};
954 }
955 2128 for my $p (@UR::Object::Type::meta_id_ref_shared_properties) {
956 25536 ▶ if (exists $params->{$p}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params->{$p}) 798 24738 25536
957 798 $params2->{$p} = $params->{$p};
958 }
959 }
960 2128 $params2->{implied_by} = $name;
961 2128 $params2->{is_specified_in_module_header} = 0;
962  
963 2128 push @id_by_names, $id_name;
964 2128 push @tmp, $id_name, $params2;
965 }
966 2128 $params->{id_by} = \@id_by_names;
967 }
968  
969 51334 ▶ if (my $id_class_by = $params->{'id_class_by'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $id_class_by = $params->{"id_class_by"}) 266 51068 51334
970 266 ▶ if (ref $id_class_by) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $id_class_by) 0 266 266
971 0 Carp::croak("Cannot initialize class $class_name: "
972 . "Property $name has an 'id_class_by' that is not a plain string");
973 }
974 266 push @tmp, $id_class_by, { implied_by => $name, is_specified_in_module_header => 0 };
975 }
976  
977 } # next property in group
978  
979 # id-by properties' metadata can influence the id-ed-by property metadata
980 26326 for my $pdata (values %$properties) {
981 58250 ▶ next unless $pdata->{id_by};
Branch: 1 branch
BranchTrueFalseTotal
unless $pdata->{"id_by"} 56122 2128 58250
982 2128 for my $id_property (@{ $pdata->{id_by} }) {
983 2128 my $id_pdata = $properties->{$id_property};
984 2128 for my $p (@UR::Object::Type::meta_id_ref_shared_properties) {
985 25536 ▶ if (exists $id_pdata->{$p} xor exists $pdata->{$p}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $id_pdata->{$p} xor exists $pdata->{$p}) { } 2926 22610 25536
elsif (not exists $id_pdata->{$p} || exists $pdata->{$p} and exists $UR::Object::Property::defaults{$p}) { } 15428 7980 23408
Condition75%3/4
exists $id_pdata->{$p} xor exists $pdata->{$p}
l&&rl&&!r!l&&r!l&&!r
7982926021812
MC/DC100%2/2
exists $id_pdata->{$p} xor exists $pdata->{$p}
exists $id_pdata->{$p} exists $pdata->{$p}
Truth table75%3/4
A xor B
A= exists $id_pdata->{$p}B= exists $pdata->{$p}
ABresult
110
101
011
000
986 # if one or the other specifies a value, copy it to the one that's missing
987 2926 ▶ $id_pdata->{$p} = $pdata->{$p} = $id_pdata->{$p} || $pdata->{$p};
Condition66%2/3
$id_pdata->{$p} || $pdata->{$p}
l!l&&r!l&&!r
79802128
MC/DC50%1/2
$id_pdata->{$p} || $pdata->{$p}
$id_pdata->{$p} $pdata->{$p}
Truth table66%2/3
A || B
A= $id_pdata->{$p}B= $pdata->{$p}
ABresult
1X1
011
000
988 ▶ } elsif (!exists $id_pdata->{$p} and !exists $pdata->{$p} and exists $UR::Object::Property::defaults{$p}) {
Condition83%5/6
not exists $id_pdata->{$p} || exists $pdata->{$p} and exists $UR::Object::Property::defaults{$p}
!ll&&!rl&&r
798638415428
exists $id_pdata->{$p} || exists $pdata->{$p}
l!l&&r!l&&!r
798021812
MC/DC66%2/3
not exists $id_pdata->{$p} || exists $pdata->{$p} and exists $UR::Object::Property::defaults{$p}
exists $id_pdata->{$p} exists $pdata->{$p} exists $UR::Object::Property::defaults{$p}
Truth table75%3/4
not(A || B) and C
A= exists $id_pdata->{$p}B= exists $pdata->{$p}C= exists $UR::Object::Property::defaults{$p}
ABCresult
1XX0
01X0
0000
0011
989 # if neither has a value, use the default for both
990 15428 $id_pdata->{$p} = $pdata->{$p} = $UR::Object::Property::defaults{$p};
991 }
992 }
993 }
994 }
995  
996 }
997 }
998  
999 0 ▶sub compose_roles {
Subroutine compose_roles: not called CC=1 SCAR=6.9
Pod undocumented
1000 0 my($class, $desc) = @_;
1001  
1002 0 UR::Role::Prototype->_apply_roles_to_class_desc($desc);
1003 0 $class->_normalize_property_descriptions_during_normalize_class_description($desc);
1004 }
1005  
1006 # Return the order to process the has, has_optional, has_constant, etc keys
1007 11966 ▶sub _class_definition_property_keys_in_processing_order {
Subroutine _class_definition_property_keys_in_processing_order: called CC=3 SCAR=11.0
1008 11966 my $class_hashref = shift;
1009  
1010 11966 my @order;
1011  
1012 # we want to hit 'id_implied' first to preserve position_ and is_specified_ keys
1013 11966 ▶ push(@order, 'id_implied') if exists $class_hashref->{id_implied};
Branch: 1 branch
BranchTrueFalseTotal
if exists $class_hashref->{"id_implied"} 1862 10104 11966
1014  
1015 # 'has' next so is_optional can get set to 0 in case the same property also appears in has_optional
1016 11966 ▶ push(@order, 'has') if exists $class_hashref->{has};
Branch: 1 branch
BranchTrueFalseTotal
if exists $class_hashref->{"has"} 11966 0 11966
1017  
1018 # everything else
1019 11966 push @order, grep { /has_|attributes_have/ } keys %$class_hashref;
1020  
1021 11966 return @order;
1022 }
1023  
1024  
1025  
1026 48408 ▶sub _normalize_property_description1 {
Subroutine _normalize_property_description1: called CC=32 SCAR=50.8
1027 48408 my $class = shift;
1028 48408 my $property_name = shift;
1029 48408 my $property_data = shift;
1030 48408 ▶ my $class_data = shift || $class;
Condition33%1/3
shift() || $class
l!l&&r!l&&!r
4840800
MC/DC0%0/2
shift() || $class
shift() $class
Truth table33%1/3
A || B
A= shift()B= $class
ABresult
1X1
011
000
1031 48408 my $class_name = $class_data->{class_name};
1032 48408 my %old_property = %$property_data;
1033 48408 my %new_class = %$class_data;
1034  
1035 48408 ▶ if (exists $old_property{unrecognized_meta_attributes}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $old_property{"unrecognized_meta_attributes"}) 0 48408 48408
1036 0 %old_property = (%{delete $old_property{unrecognized_meta_attributes}}, %old_property);
1037 }
1038  
1039 48408 delete $old_property{source};
1040  
1041 48408 ▶ if ($old_property{implied_by} and $old_property{implied_by} eq $property_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($old_property{"implied_by"} and $old_property{"implied_by"} eq $property_name) 0 48408 48408
Condition66%2/3
$old_property{"implied_by"} and $old_property{"implied_by"} eq $property_name
!ll&&!rl&&r
4628021280
MC/DC0%0/2
$old_property{"implied_by"} and $old_property{"implied_by"} eq $property_name
$old_property{"implied_by"} $old_property{"implied_by"} eq $property_name
Truth table66%2/3
A and B
A= $old_property{"implied_by"}B= $old_property{"implied_by"} eq $property_name
ABresult
0X0
100
111
1042 0 $class->warning_message("Cleaning up odd self-referential 'implied_by' on $class_name $property_name");
1043 0 delete $old_property{implied_by};
1044 }
1045  
1046 # Only 1 of is_abstract, is_concrete or is_final may be set
1047 {
1048 266 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1049 my $modifier_sum = $old_property{is_abstract}
1050 + $old_property{is_concrete}
1051 48408 + $old_property{is_final};
1052  
1053 48408 ▶ if ($modifier_sum > 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($modifier_sum > 1) { } 0 48408 48408
elsif ($modifier_sum == 0) { } 48408 0 48408
1054 0 Carp::confess("abstract/concrete/final are mutually exclusive. Error in class definition for $class_name property $property_name!");
1055 } elsif ($modifier_sum == 0) {
1056 48408 $old_property{is_concrete} = 1;
1057 }
1058 }
1059  
1060 48408 my %new_property = (
1061 class_name => $class_name,
1062 property_name => $property_name,
1063 );
1064  
1065 48408 for my $mapping (
1066 [ property_type => qw/resolution/],
1067 [ class_name => qw//],
1068 [ property_name => qw//],
1069 [ column_name => qw/sql/],
1070 [ constraint_name => qw//],
1071 [ data_length => qw/len/],
1072 [ data_type => qw/type is isa is_a/],
1073 [ calculated_default => qw//],
1074 [ default_value => qw/default value/],
1075 [ valid_values => qw//],
1076 [ example_values => qw//],
1077 [ doc => qw/description/],
1078 [ is_optional => qw/is_nullable nullable optional/],
1079 [ is_transient => qw//],
1080 [ is_volatile => qw//],
1081 [ is_constant => qw//],
1082 [ is_classwide => qw/is_class_wide/],
1083 [ is_delegated => qw//],
1084 [ is_calculated => qw//],
1085 [ is_mutable => qw//],
1086 [ is_transactional => qw//],
1087 [ is_abstract => qw//],
1088 [ is_concrete => qw//],
1089 [ is_final => qw//],
1090 [ is_many => qw//],
1091 [ is_deprecated => qw//],
1092 [ is_undocumented => qw//],
1093 [ is_numeric => qw//],
1094 [ is_id => qw//],
1095 [ id_by => qw//],
1096 [ id_class_by => qw//],
1097 [ specify_by => qw//],
1098 [ order_by => qw//],
1099 [ access_as => qw//],
1100 [ via => qw//],
1101 [ to => qw//],
1102 [ where => qw/restrict filter/],
1103 [ implied_by => qw//],
1104 [ calculate => qw//],
1105 [ calculate_from => qw//],
1106 [ calculate_perl => qw/calc_perl/],
1107 [ calculate_sql => qw/calc_sql/],
1108 [ calculate_js => qw//],
1109 [ reverse_as => qw/reverse_id_by im_its/],
1110 [ is_legacy_eav => qw//],
1111 [ is_dimension => qw//],
1112 [ is_specified_in_module_header => qw//],
1113 [ position_in_module_header => qw//],
1114 [ singular_name => qw//],
1115 [ plural_name => qw//],
1116 ) {
1117 2420400 my $primary_field_name = $mapping->[0];
1118  
1119 2420400 my $found_key;
1120 2420400 foreach my $key ( @$mapping ) {
1121 3388560 ▶ if (exists $old_property{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $old_property{$key}) 304551 3084009 3388560
1122 304551 ▶ if ($found_key) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found_key) 0 304551 304551
1123 0 my @keys = grep { exists $old_property{$_} } @$mapping;
1124 0 Carp::croak("Invalid class definition for $class_name in property '$property_name'. The keys "
1125 . join(', ',$found_key,@keys) . " are all synonyms for $primary_field_name");
1126 }
1127 304551 $found_key = $key;
1128 }
1129 }
1130  
1131 2420400 ▶ if ($found_key) {
Branch: 2 branches
BranchTrueFalseTotal
if ($found_key) { } 304551 2115849 2420400
elsif (exists $UR::Object::Property::defaults{$primary_field_name}) { } 560145 1555704 2115849
1132 304551 $new_property{$primary_field_name} = delete $old_property{$found_key};
1133 } elsif (exists $UR::Object::Property::defaults{$primary_field_name}) {
1134 560145 $new_property{$primary_field_name} = $UR::Object::Property::defaults{$primary_field_name};
1135 }
1136 }
1137  
1138 48408 ▶ if (my $data = delete $old_property{delegate}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $data = delete $old_property{"delegate"}) 0 48408 48408
1139 0 ▶ if ($data->{via} =~ /^eav_/ and $data->{to} eq 'value') {
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{'via'} =~ /^eav_/ and $data->{'to'} eq 'value') { } 0 0 0
Condition0%0/3
$data->{"via"} =~ /^eav_/ and $data->{"to"} eq "value"
!ll&&!rl&&r
000
MC/DC0%0/2
$data->{"via"} =~ /^eav_/ and $data->{"to"} eq "value"
$data->{"via"} =~ /^eav_/ $data->{"to"} eq "value"
Truth table0%0/3
A and B
A= $data->{"via"} =~ /^eav_/B= $data->{"to"} eq "value"
ABresult
0X0
100
111
1140 0 $new_property{is_legacy_eav} = 1;
1141 }
1142 else {
1143 0 die "Odd delegation for $property_name: "
1144 . Data::Dumper::Dumper($data);
1145 }
1146 }
1147  
1148 48408 ▶ if ($new_property{default_value} && $new_property{calculated_default}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_property{"default_value"} and $new_property{"calculated_default"}) 0 48408 48408
Condition66%2/3
$new_property{"default_value"} and $new_property{"calculated_default"}
!ll&&!rl&&r
4521731910
MC/DC0%0/2
$new_property{"default_value"} and $new_property{"calculated_default"}
$new_property{"default_value"} $new_property{"calculated_default"}
Truth table66%2/3
A and B
A= $new_property{"default_value"}B= $new_property{"calculated_default"}
ABresult
0X0
100
111
1149 0 die qq(Can't initialize class $class_name: Property '$new_property{property_name}' has both default_value and calculated_default specified.);
1150 }
1151  
1152 48408 ▶ if ($new_property{calculated_default}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_property{"calculated_default"}) 0 48408 48408
1153 0 ▶ if ($new_property{calculated_default} eq 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_property{"calculated_default"} eq 1) 0 0 0
1154 0 $new_property{calculated_default} = '__default_' . $new_property{property_name} . '__';
1155 }
1156  
1157 0 my $ref = ref $new_property{calculated_default};
1158 0 ▶ if ($ref and $ref ne 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref and $ref ne "CODE") 0 0 0
Condition0%0/3
$ref and $ref ne "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
$ref and $ref ne "CODE"
$ref $ref ne "CODE"
Truth table0%0/3
A and B
A= $refB= $ref ne "CODE"
ABresult
0X0
100
111
1159 0 die qq(Can't initialize class $class_name: Property '$new_property{property_name}' has calculated_default specified as a $ref ref but it must be a method name or coderef.);
1160 }
1161  
1162 0 ▶ unless ($ref) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ref) 0 0 0
1163 0 my $method = $class_name->can($new_property{calculated_default});
1164 0 ▶ unless ($method) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($method) 0 0 0
1165 0 die qq(Can't initialize class $class_name: Property '$new_property{property_name}' has calculated_default specified as '$new_property{calculated_default}' but method does not exist.);
1166 }
1167 0 $new_property{calculated_default} = $method;
1168 }
1169 }
1170  
1171 48408 ▶ if ($new_property{id_by} && $new_property{reverse_as}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_property{"id_by"} and $new_property{"reverse_as"}) 0 48408 48408
Condition66%2/3
$new_property{"id_by"} and $new_property{"reverse_as"}
!ll&&!rl&&r
4628021280
MC/DC0%0/2
$new_property{"id_by"} and $new_property{"reverse_as"}
$new_property{"id_by"} $new_property{"reverse_as"}
Truth table66%2/3
A and B
A= $new_property{"id_by"}B= $new_property{"reverse_as"}
ABresult
0X0
100
111
1172 0 die qq(Can't initialize class $class_name: Property '$new_property{property_name}' has both id_by and reverse_as specified.);
1173 }
1174  
1175 48408 ▶ if ($new_property{data_type}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_property{"data_type"}) 35109 13299 48408
1176 35109 ▶ if (my (undef, $length) = $new_property{data_type} =~ m/(\s*)\((\d+)\)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(undef, $length) = $new_property{"data_type"} =~ /(\s*)\((\d+)\)$/) 0 35109 35109
1177 0 $new_property{data_length} = $length;
1178 }
1179 35109 ▶ if ($new_property{data_type} =~ m/[^\w:]/
Branch: 1 branch
BranchTrueFalseTotal
if ($new_property{"data_type"} =~ /[^\w:]/ and not ref $new_property{"data_type"} && $new_property{"data_type"}->isa("UR::Role::Param")) 0 35109 35109
Condition16%1/6
$new_property{"data_type"} =~ /[^\w:]/ and not ref $new_property{"data_type"} && $new_property{"data_type"}->isa("UR::Role::Param")
!ll&&!rl&&r
3510900
ref $new_property{'data_type'} && $new_property{'data_type'}->isa('UR::Role::Param')
!ll&&!rl&&r
000
MC/DC0%0/3
$new_property{"data_type"} =~ /[^\w:]/ and not ref $new_property{"data_type"} && $new_property{"data_type"}->isa("UR::Role::Param")
$new_property{"data_type"} =~ /[^\w:]/ ref $new_property{'data_type'} $new_property{'data_type'}->isa('UR::Role::Param')
Truth table25%1/4
A and not(B && C)
A= $new_property{"data_type"} =~ /[^\w:]/B= ref $new_property{'data_type'}C= $new_property{'data_type'}->isa('UR::Role::Param')
ABCresult
0XX0
1110
10X1
1101
1180 and
1181 (!ref($new_property{data_type}) or !$new_property{data_type}->isa('UR::Role::Param'))
1182 ) {
1183 Carp::croak("Can't initialize class $class_name: Property '" . $new_property{property_name}
1184 0 . "' has metadata for is/data_type that does not look like a class name ($new_property{data_type})");
1185 }
1186 }
1187  
1188 48408 ▶ if (%old_property) {
Branch: 1 branch
BranchTrueFalseTotal
if (%old_property) 0 48408 48408
1189 0 $new_property{unrecognized_meta_attributes} = \%old_property;
1190 0 %new_property = (%old_property, %new_property);
1191 }
1192  
1193 48408 return %new_property;
1194 }
1195  
1196 48408 ▶sub _normalize_property_description2 {
Subroutine _normalize_property_description2: called CC=36 SCAR=51.2
1197 48408 my $class = shift;
1198 48408 my $property_data = shift;
1199 48408 ▶ my $class_data = shift || $class;
Condition33%1/3
shift() || $class
l!l&&r!l&&!r
4840800
MC/DC0%0/2
shift() || $class
shift() $class
Truth table33%1/3
A || B
A= shift()B= $class
ABresult
1X1
011
000
1200  
1201 48408 my $property_name = $property_data->{property_name};
1202 48408 my $class_name = $property_data->{class_name};
1203  
1204 48408 my %new_property = %$property_data;
1205 48408 my %new_class = %$class_data;
1206  
1207 48408 ▶ if (grep { $_ ne 'is_calculated' && $_ ne 'calculated_default' && /calc/ } keys %new_property) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ ne "is_calculated" and $_ ne "calculated_default" and /calc/;} keys %new_property) 1064 47344 48408
Condition83%5/6
$_ ne 'is_calculated' && $_ ne 'calculated_default' && /calc/
!ll&&!rl&&r
484089120401064
$_ ne "is_calculated" and $_ ne "calculated_default"
!ll&&!rl&&r
484080913104
MC/DC66%2/3
$_ ne 'is_calculated' && $_ ne 'calculated_default' && /calc/
$_ ne "is_calculated" $_ ne "calculated_default" /calc/
Truth table75%3/4
A and B && C
A= $_ ne "is_calculated"B= $_ ne "calculated_default"C= /calc/
ABCresult
0XX0
10X0
1100
1111
1208 1064 $new_property{is_calculated} = 1;
1209 }
1210  
1211 48408 ▶ if ($new_property{via}
Branch: 1 branch
BranchTrueFalseTotal
if ($new_property{"via"} or $new_property{"to"} or $new_property{"id_by"} or $new_property{"reverse_as"}) 13034 35374 48408
Condition88%8/9
$new_property{"via"} or $new_property{"to"} or $new_property{"id_by"} or $new_property{"reverse_as"}
l!l&&r!l&&!r
1223679835374
$new_property{"via"} or $new_property{"to"} or $new_property{"id_by"}
l!l&&r!l&&!r
10108212836172
$new_property{"via"} or $new_property{"to"}
l!l&&r!l&&!r
10108038300
MC/DC75%3/4
$new_property{"via"} or $new_property{"to"} or $new_property{"id_by"} or $new_property{"reverse_as"}
$new_property{"via"} $new_property{"to"} $new_property{"id_by"} $new_property{"reverse_as"}
Truth table80%4/5
A or B or C or D
A= $new_property{"via"}B= $new_property{"to"}C= $new_property{"id_by"}D= $new_property{"reverse_as"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1212 || $new_property{to}
1213 || $new_property{id_by}
1214 || $new_property{reverse_as}
1215 ) {
1216 13034 $new_property{is_delegated} = 1;
1217 13034 ▶ if (defined $new_property{via} and not defined $new_property{to}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new_property{"via"} and not defined $new_property{"to"}) 1862 11172 13034
Condition100%3/3
defined $new_property{"via"} and not defined $new_property{"to"}
!ll&&!rl&&r
292682461862
MC/DC100%2/2
defined $new_property{"via"} and not defined $new_property{"to"}
defined $new_property{"via"} not defined $new_property{"to"}
Truth table100%3/3
A and not(B)
A= defined $new_property{"via"}B= not defined $new_property{"to"}
ABresult
0X0
100
111
1218 1862 $new_property{to} = $property_name;
1219 }
1220 }
1221  
1222 48408 ▶ if (!defined($new_property{is_mutable})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $new_property{"is_mutable"}) 47876 532 48408
1223 47876 ▶ if ($new_property{is_delegated}
Branch: 1 branch
BranchTrueFalseTotal
if ($new_property{'is_delegated'} or defined $class_data->{'subclassify_by'} and $class_data->{'subclassify_by'} eq $property_name) { } 13034 34842 47876
Condition50%3/6
$new_property{"is_delegated"} or defined $class_data->{"subclassify_by"} and $class_data->{"subclassify_by"} eq $property_name
l!l&&r!l&&!r
13034034842
defined $class_data->{"subclassify_by"} and $class_data->{"subclassify_by"} eq $property_name
!ll&&!rl&&r
3484200
MC/DC33%1/3
$new_property{"is_delegated"} or defined $class_data->{"subclassify_by"} and $class_data->{"subclassify_by"} eq $property_name
$new_property{"is_delegated"} defined $class_data->{"subclassify_by"} $class_data->{"subclassify_by"} eq $property_name
Truth table50%2/4
A or B and C
A= $new_property{"is_delegated"}B= defined $class_data->{"subclassify_by"}C= $class_data->{"subclassify_by"} eq $property_name
ABCresult
1XX1
0111
00X0
0100
1224 or
1225 (defined $class_data->{'subclassify_by'} and $class_data->{'subclassify_by'} eq $property_name)
1226 ) {
1227 13034 $new_property{is_mutable} = 0;
1228 }
1229 else {
1230 34842 $new_property{is_mutable} = 1;
1231 }
1232 }
1233  
1234 # For classes that have (or pretend to have) tables, the Property objects
1235 # should get their column_name property automatically filled in
1236 48408 my $the_data_source;
1237 48408 ▶ if (ref($new_class{'data_source_id'}) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $new_class{'data_source_id'} eq 'HASH') { } 0 48408 48408
elsif ($new_class{'data_source_id'}) { } 0 48408 48408
1238 # This is an inline-defined data source
1239 0 $the_data_source = $new_class{'data_source_id'}->{'is'};
1240 } elsif ($new_class{'data_source_id'}) {
1241 0 $the_data_source = $new_class{'data_source_id'};
1242 # using local() here to save $@ doesn't work. You end up with the
1243 # error "Unknown error" if one of the parent classes of the data source has
1244 # some kind of problem
1245 0 my $dollarat = $@;
1246 0 $@ = '';
1247 0 ▶ $the_data_source = UR::DataSource->get($the_data_source) || eval { $the_data_source->get() };
Condition0%0/3
'UR::DataSource'->get($the_data_source) || eval { do { $the_data_source->get } }
l!l&&r!l&&!r
000
MC/DC0%0/2
'UR::DataSource'->get($the_data_source) || eval { do { $the_data_source->get } }
'UR::DataSource'->get($the_data_source) eval { do { $the_data_source->get } }
Truth table0%0/3
A || B
A= 'UR::DataSource'->get($the_data_source)B= eval { do { $the_data_source->get } }
ABresult
1X1
011
000
1248 0 ▶ unless ($the_data_source) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($the_data_source) 0 0 0
1249 my $error = "Can't resolve data source from value '"
1250 0 . $new_class{'data_source_id'}
1251 . "' in class definition for $class_name";
1252 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1253 0 $error .= "\n$@";
1254 }
1255 0 Carp::croak($error);
1256 }
1257 0 $@ = $dollarat;
1258 }
1259 # UR::DataSource::File-backed classes don't have table_names, but for querying/saving to
1260 # work property, their properties still have to have column_name filled in
1261 48408 ▶ if (($new_class{table_name} or ($the_data_source and ($the_data_source->initializer_should_create_column_name_for_class_properties())))
Branch: 1 branch
BranchTrueFalseTotal
if ($new_class{"table_name"} || $the_data_source && $the_data_source->initializer_should_create_column_name_for_class_properties and not exists $new_property{"column_name"} and not $new_property{"is_transient"} and not $new_property{"is_delegated"} and not $new_property{"is_calculated"} and not $new_property{"is_legacy_eav"}) 0 48408 48408
Condition33%7/21
$new_class{"table_name"} || $the_data_source && $the_data_source->initializer_should_create_column_name_for_class_properties and not exists $new_property{"column_name"} and not $new_property{"is_transient"} and not $new_property{"is_delegated"} and not $new_property{"is_calculated"} and not $new_property{"is_legacy_eav"}
!ll&&!rl&&r
4840800
$new_class{"table_name"} || $the_data_source && $the_data_source->initializer_should_create_column_name_for_class_properties and not exists $new_property{"column_name"} and not $new_property{"is_transient"} and not $new_property{"is_delegated"} and not $new_property{"is_calculated"}
!ll&&!rl&&r
4840800
$new_class{"table_name"} || $the_data_source && $the_data_source->initializer_should_create_column_name_for_class_properties and not exists $new_property{"column_name"} and not $new_property{"is_transient"} and not $new_property{"is_delegated"}
!ll&&!rl&&r
4840800
$new_class{"table_name"} || $the_data_source && $the_data_source->initializer_should_create_column_name_for_class_properties and not exists $new_property{"column_name"} and not $new_property{"is_transient"}
!ll&&!rl&&r
4840800
$new_class{"table_name"} || $the_data_source && $the_data_source->initializer_should_create_column_name_for_class_properties and not exists $new_property{"column_name"}
!ll&&!rl&&r
4840800
$new_class{"table_name"} or $the_data_source and $the_data_source->initializer_should_create_column_name_for_class_properties
l!l&&r!l&&!r
0048408
$the_data_source and $the_data_source->initializer_should_create_column_name_for_class_properties
!ll&&!rl&&r
4840800
MC/DC0%0/8
$new_class{"table_name"} || $the_data_source && $the_data_source->initializer_should_create_column_name_for_class_properties and not exists $new_property{"column_name"} and not $new_property{"is_transient"} and not $new_property{"is_delegated"} and not $new_property{"is_calculated"} and not $new_property{"is_legacy_eav"}
$new_class{"table_name"} $the_data_source $the_data_source->initializer_should_create_column_name_for_class_properties not exists $new_property{"column_name"} not $new_property{"is_transient"} not $new_property{"is_delegated"} not $new_property{"is_calculated"} not $new_property{"is_legacy_eav"}
Truth table7%1/14
A or B and C and not(D) and not(E) and not(F) and not(G) and not(H)
A= $new_class{"table_name"}B= $the_data_sourceC= $the_data_source->initializer_should_create_column_name_for_class_propertiesD= not exists $new_property{"column_name"}E= not $new_property{"is_transient"}F= not $new_property{"is_delegated"}G= not $new_property{"is_calculated"}H= not $new_property{"is_legacy_eav"}
ABCDEFGHresult
00XXXXXX0
010XXXXX0
1XX0XXXX0
0110XXXX0
1XX10XXX0
01110XXX0
1XX110XX0
011110XX0
1XX1110X0
0111110X0
1XX111100
011111100
1XX111111
011111111
1262 and not exists($new_property{column_name}) # They didn't supply a column_name
1263 and not $new_property{is_transient}
1264 and not $new_property{is_delegated}
1265 and not $new_property{is_calculated}
1266 and not $new_property{is_legacy_eav}
1267 ) {
1268 0 $new_property{column_name} = $new_property{property_name};
1269 0 ▶ if ($the_data_source and $the_data_source->table_and_column_names_are_upper_case) {
Branch: 1 branch
BranchTrueFalseTotal
if ($the_data_source and $the_data_source->table_and_column_names_are_upper_case) 0 0 0
Condition0%0/3
$the_data_source and $the_data_source->table_and_column_names_are_upper_case
!ll&&!rl&&r
000
MC/DC0%0/2
$the_data_source and $the_data_source->table_and_column_names_are_upper_case
$the_data_source $the_data_source->table_and_column_names_are_upper_case
Truth table0%0/3
A and B
A= $the_data_sourceB= $the_data_source->table_and_column_names_are_upper_case
ABresult
0X0
100
111
1270 0 $new_property{column_name} = uc($new_property{column_name});
1271 }
1272 }
1273  
1274 48408 ▶ if ($new_property{order_by} and not $new_property{is_many}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_property{"order_by"} and not $new_property{"is_many"}) 0 48408 48408
Condition33%1/3
$new_property{"order_by"} and not $new_property{"is_many"}
!ll&&!rl&&r
4840800
MC/DC0%0/2
$new_property{"order_by"} and not $new_property{"is_many"}
$new_property{"order_by"} not $new_property{"is_many"}
Truth table33%1/3
A and not(B)
A= $new_property{"order_by"}B= not $new_property{"is_many"}
ABresult
0X0
100
111
1275 0 die "Cannot use order_by except on is_many properties!";
1276 }
1277  
1278 48408 ▶ if ($new_property{specify_by} and not $new_property{is_many}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_property{"specify_by"} and not $new_property{"is_many"}) 0 48408 48408
Condition33%1/3
$new_property{"specify_by"} and not $new_property{"is_many"}
!ll&&!rl&&r
4840800
MC/DC0%0/2
$new_property{"specify_by"} and not $new_property{"is_many"}
$new_property{"specify_by"} not $new_property{"is_many"}
Truth table33%1/3
A and not(B)
A= $new_property{"specify_by"}B= not $new_property{"is_many"}
ABresult
0X0
100
111
1279 0 die "Cannot use specify_by except on is_many properties!";
1280 }
1281  
1282 48408 ▶ if ($new_property{implied_by} and $new_property{implied_by} eq $property_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_property{"implied_by"} and $new_property{"implied_by"} eq $property_name) 0 48408 48408
Condition66%2/3
$new_property{"implied_by"} and $new_property{"implied_by"} eq $property_name
!ll&&!rl&&r
4628021280
MC/DC0%0/2
$new_property{"implied_by"} and $new_property{"implied_by"} eq $property_name
$new_property{"implied_by"} $new_property{"implied_by"} eq $property_name
Truth table66%2/3
A and B
A= $new_property{"implied_by"}B= $new_property{"implied_by"} eq $property_name
ABresult
0X0
100
111
1283 0 $class->warnings_message("New data has odd self-referential 'implied_by' on $class_name $property_name!");
1284 0 delete $new_property{implied_by};
1285 }
1286  
1287 48408 return %new_property;
1288 }
1289  
1290  
1291 11966 ▶sub _make_minimal_class_from_normalized_class_description {
Subroutine _make_minimal_class_from_normalized_class_description: called CC=5 SCAR=16.4
1292 11966 my $class = shift;
1293 11966 my $desc = shift;
1294  
1295 11966 my $class_name = $desc->{class_name};
1296 11966 ▶ unless ($class_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class_name) 0 11966 11966
1297 0 Carp::confess("No class name specified?");
1298 }
1299  
1300 11966 my $meta_class_name = $desc->{meta_class_name};
1301 11966 ▶ die unless $meta_class_name;
Branch: 1 branch
BranchTrueFalseTotal
unless $meta_class_name 0 11966 11966
1302 11966 ▶ if ($meta_class_name ne __PACKAGE__) {
Branch: 1 branch
BranchTrueFalseTotal
if ($meta_class_name ne __PACKAGE__) 5584 6382 11966
1303 5584 ▶ unless (
Branch: 1 branch
BranchTrueFalseTotal
unless ($meta_class_name->isa(__PACKAGE__)) 0 5584 5584
1304 $meta_class_name->isa(__PACKAGE__)
1305 ) {
1306 0 warn "Bogus meta class $meta_class_name doesn't inherit from UR::Object::Type?"
1307 }
1308 }
1309  
1310 # only do this when the classes match
1311 # when they do not match, the super-class has already called this by delegating to the correct subclass
1312 11966 $class_name::VERSION = 2.0; # No BumpVersion
1313  
1314 11966 my $self = bless { id => $class_name, %$desc }, $meta_class_name;
1315  
1316 11966 $UR::Context::all_objects_loaded->{$meta_class_name}{$class_name} = $self;
1317 11966 my $full_name = join( '::', $class_name, '__meta__' );
1318 Sub::Install::reinstall_sub({
1319 into => $class_name,
1320 as => '__meta__',
1321 43936 ▶ code => Sub::Name::subname $full_name => sub {$self},
Subroutine __meta__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
1322 11966 });
1323  
1324 11966 return $self;
1325 }
1326  
1327 11966 ▶sub _initialize_accessors_and_inheritance {
Subroutine _initialize_accessors_and_inheritance: called CC=15 SCAR=36.3
1328 11966 my $self = shift;
1329  
1330 11966 $self->initialize_direct_accessors;
1331  
1332 11966 my $class_name = $self->{class_name};
1333  
1334 11966 my @is = @{ $self->{is} };
1335 11966 ▶ unless (@is) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@is) 266 11700 11966
1336 266 @is = ('UR::ModuleBase')
1337 }
1338 11966 eval "\@${class_name}::ISA = (" . join(',', map { "'$_'" } @is) . ")\n";
1339 11966 ▶ Carp::croak("Can't initialize \@ISA for class_name '$class_name': $@\nMaybe the class_name or one of the parent classes are not valid class names") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 11966 11966
1340  
1341 11966 my $namespace_mro;
1342 11966 my $namespace_name = $self->{namespace};
1343 11966 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not $UR::Object::Type::bootstrapping || $class_name->isa("UR::Namespace") and $namespace_name and $namespace_name->isa("UR::Namespace") and $namespace_name->can("get") and my $namespace = $namespace_name->get) 0 11966 11966
Condition33%5/15
not $UR::Object::Type::bootstrapping || $class_name->isa("UR::Namespace") and $namespace_name and $namespace_name->isa("UR::Namespace") and $namespace_name->can("get") and my $namespace = $namespace_name->get
!ll&&!rl&&r
1196600
not $UR::Object::Type::bootstrapping || $class_name->isa("UR::Namespace") and $namespace_name and $namespace_name->isa("UR::Namespace") and $namespace_name->can("get")
!ll&&!rl&&r
1196600
not $UR::Object::Type::bootstrapping || $class_name->isa("UR::Namespace") and $namespace_name and $namespace_name->isa("UR::Namespace")
!ll&&!rl&&r
1196600
not $UR::Object::Type::bootstrapping || $class_name->isa("UR::Namespace") and $namespace_name
!ll&&!rl&&r
1196600
$UR::Object::Type::bootstrapping || $class_name->isa('UR::Namespace')
l!l&&r!l&&!r
1196600
MC/DC0%0/6
not $UR::Object::Type::bootstrapping || $class_name->isa("UR::Namespace") and $namespace_name and $namespace_name->isa("UR::Namespace") and $namespace_name->can("get") and my $namespace = $namespace_name->get
$UR::Object::Type::bootstrapping $class_name->isa('UR::Namespace') $namespace_name $namespace_name->isa("UR::Namespace") $namespace_name->can("get") my $namespace = $namespace_name->get
Truth table14%1/7
not(A || B) and C and D and E and F
A= $UR::Object::Type::bootstrappingB= $class_name->isa('UR::Namespace')C= $namespace_nameD= $namespace_name->isa("UR::Namespace")E= $namespace_name->can("get")F= my $namespace = $namespace_name->get
ABCDEFresult
1XXXXX0
01XXXX0
000XXX0
0010XX0
00110X0
0011100
0011111
1344 !$bootstrapping
1345 && !$class_name->isa('UR::Namespace')
1346 && $namespace_name
1347 && $namespace_name->isa('UR::Namespace')
1348 && $namespace_name->can('get')
1349 && (my $namespace = $namespace_name->get())
1350 ) {
1351 0 $namespace_mro = $namespace->method_resolution_order;
1352 }
1353  
1354 11966 ▶ if ($^V lt v5.9.5 && $namespace_mro && $namespace_mro eq 'c3') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^V lt v5.9.5 and $namespace_mro and $namespace_mro eq "c3") 0 11966 11966
Condition33%2/6
$^V lt v5.9.5 and $namespace_mro and $namespace_mro eq "c3"
!ll&&!rl&&r
1196600
$^V lt v5.9.5 and $namespace_mro
!ll&&!rl&&r
1196600
MC/DC0%0/3
$^V lt v5.9.5 and $namespace_mro and $namespace_mro eq "c3"
$^V lt v5.9.5 $namespace_mro $namespace_mro eq "c3"
Truth table25%1/4
A and B and C
A= $^V lt v5.9.5B= $namespace_mroC= $namespace_mro eq "c3"
ABCresult
0XX0
10X0
1100
1111
1355 0 warn "C3 method resolution order is not supported on Perl < 5.9.5. Reverting $namespace_name namespace to DFS.";
1356 0 my $namespace = $namespace_name->get();
1357 0 $namespace_mro = $namespace->method_resolution_order('dfs');
1358 }
1359  
1360 11966 ▶ if ($^V ge v5.9.5 && $namespace_mro && mro::get_mro($class_name) ne $namespace_mro) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^V ge v5.9.5 and $namespace_mro and &mro::get_mro($class_name) ne $namespace_mro) 0 11966 11966
Condition33%2/6
$^V ge v5.9.5 and $namespace_mro and &mro::get_mro($class_name) ne $namespace_mro
!ll&&!rl&&r
1196600
$^V ge v5.9.5 and $namespace_mro
!ll&&!rl&&r
0119660
MC/DC0%0/3
$^V ge v5.9.5 and $namespace_mro and &mro::get_mro($class_name) ne $namespace_mro
$^V ge v5.9.5 $namespace_mro &mro::get_mro($class_name) ne $namespace_mro
Truth table25%1/4
A and B and C
A= $^V ge v5.9.5B= $namespace_mroC= &mro::get_mro($class_name) ne $namespace_mro
ABCresult
0XX0
10X0
1100
1111
1361 0 mro::set_mro($class_name, $namespace_mro);
1362 }
1363  
1364 11966 return $self;
1365 }
1366  
1367 143 our %_init_subclasses_loaded;
1368 266 ▶sub subclasses_loaded {
Subroutine subclasses_loaded: called CC=1 SCAR=0.0
Pod undocumented
1369 266 return @{ $_init_subclasses_loaded{shift->class_name}};
1370 }
1371  
1372 143 our %_inform_all_parent_classes_of_newly_loaded_subclass;
1373 11966 ▶sub _inform_all_parent_classes_of_newly_loaded_subclass {
Subroutine _inform_all_parent_classes_of_newly_loaded_subclass: called CC=12 SCAR=26.1
1374 11966 my $self = shift;
1375 11966 my $class_name = $self->class_name;
1376  
1377 11966 ▶ Carp::confess("re-initializing class $class_name") if $_inform_all_parent_classes_of_newly_loaded_subclass{$class_name};
Branch: 1 branch
BranchTrueFalseTotal
if $UR::Object::Type::_inform_all_parent_classes_of_newly_loaded_subclass{$class_name} 0 11966 11966
1378 11966 $_inform_all_parent_classes_of_newly_loaded_subclass{$class_name} = 1;
1379  
1380 266 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1381 266 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1382 11966 my @parent_classes = @{ $class_name . "::ISA" };
1383 11966 for my $parent_class (@parent_classes) {
1384 11966 ▶ unless ($parent_class->can("id")) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($parent_class->can("id")) 266 11700 11966
1385 266 __PACKAGE__->use_module_with_namespace_constraints($parent_class);
1386 266 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 266 266
1387 0 die "Failed to find parent_class $parent_class for $class_name!";
1388 }
1389 }
1390 }
1391  
1392 11966 my @i = sort $class_name->inheritance;
1393 11966 ▶ $_init_subclasses_loaded{$class_name} ||= [];
Condition100%2/2
$UR::Object::Type::_init_subclasses_loaded{$class_name} ||= []
l!l
106310903
MC/DC100%1/1
$UR::Object::Type::_init_subclasses_loaded{$class_name} ||= []
$UR::Object::Type::_init_subclasses_loaded{$class_name}
Truth table100%2/2
A
A= $UR::Object::Type::_init_subclasses_loaded{$class_name}
Aresult
11
00
1394 11966 my $last_parent_class = "";
1395 11966 for my $parent_class (@i) {
1396 34301 ▶ next if $parent_class eq $last_parent_class;
Branch: 1 branch
BranchTrueFalseTotal
if $parent_class eq $last_parent_class 0 34301 34301
1397  
1398 34301 $last_parent_class = $parent_class;
1399 34301 ▶ $_init_subclasses_loaded{$parent_class} ||= [];
Condition100%2/2
$UR::Object::Type::_init_subclasses_loaded{$parent_class} ||= []
l!l
329721329
MC/DC100%1/1
$UR::Object::Type::_init_subclasses_loaded{$parent_class} ||= []
$UR::Object::Type::_init_subclasses_loaded{$parent_class}
Truth table100%2/2
A
A= $UR::Object::Type::_init_subclasses_loaded{$parent_class}
Aresult
11
00
1400 34301 push @{ $_init_subclasses_loaded{$parent_class} }, $class_name;
1401 34301 push @{ $parent_class . "::_init_subclasses_loaded" }, $class_name;
1402  
1403 # any index on a parent class must move to the child class
1404 # if the child class were loaded before the index is made, it is pushed down at index creation time
1405 34301 ▶ if (my $parent_index_hashrefs = $UR::Object::Index::all_by_class_name_and_property_name{$parent_class}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $parent_index_hashrefs = $UR::Object::Index::all_by_class_name_and_property_name{$parent_class}) 0 34301 34301
1406 #print "PUSHING INDEXES FOR $parent_class to $class_name\n";
1407 0 for my $parent_property (keys %$parent_index_hashrefs) {
1408 0 my $parent_indexes = $parent_index_hashrefs->{$parent_property};
1409 0 ▶ my $indexes = $UR::Object::Index::all_by_class_name_and_property_name{$class_name}{$parent_property} ||= [];
Condition0%0/2
$UR::Object::Index::all_by_class_name_and_property_name{$class_name}{$parent_property} ||= []
l!l
00
MC/DC0%0/1
$UR::Object::Index::all_by_class_name_and_property_name{$class_name}{$parent_property} ||= []
$UR::Object::Index::all_by_class_name_and_property_name{$class_name}{$parent_property}
Truth table0%0/2
A
A= $UR::Object::Index::all_by_class_name_and_property_name{$class_name}{$parent_property}
Aresult
11
00
1410 0 push @$indexes, @$parent_indexes;
1411 }
1412 }
1413 }
1414  
1415 11966 return 1;
1416 }
1417  
1418 11966 ▶sub _inform_roles_of_new_class {
Subroutine _inform_roles_of_new_class: called CC=3 SCAR=16.5
1419 11966 my $self = shift;
1420  
1421 11966 foreach my $role_obj ( @{ $self->{roles} } ) {
1422 0 my $package = $role_obj->role_name;
1423 0 ▶ next unless my $import = $package->can('__import__');
Branch: 1 branch
BranchTrueFalseTotal
unless my $import = $package->can("__import__") 0 0 0
1424 0 $import->($package, $self);
1425 }
1426 }
1427  
1428 266 ▶sub _complete_class_meta_object_definitions {
Subroutine _complete_class_meta_object_definitions: called CC=66 SCAR=75.6
1429 266 my $self = shift;
1430  
1431 # track related objects
1432 266 my @subordinate_objects;
1433  
1434 # grab some data from the object
1435 266 my $class_name = $self->{class_name};
1436 266 my $table_name = $self->{table_name};
1437  
1438 # decompose the embedded complex data structures into normalized objects
1439 266 my $inheritance = $self->{is};
1440 266 my $properties = $self->{has};
1441 266 ▶ my $relationships = $self->{relationships} || [];
Condition50%1/2
$self->{'relationships'} || []
l!l
2660
MC/DC0%0/1
$self->{'relationships'} || []
$self->{'relationships'}
Truth table50%1/2
A
A= $self->{'relationships'}
Aresult
11
00
1442 266 my $constraints = $self->{constraints};
1443 266 my $data_source = $self->{'data_source_id'};
1444  
1445 266 my $id_properties = $self->{id_by};
1446 266 my %id_property_rank;
1447 266 ▶ for (my $i = '0 but true'; $i < @$id_properties; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$id_properties) 0 266 266
1448 0 $id_property_rank{$id_properties->[$i]} = $i;
1449 }
1450  
1451 # mark id/non-id properites
1452 266 foreach my $pinfo ( values %$properties ) {
1453 0 $pinfo->{'is_id'} = $id_property_rank{$pinfo->{'property_name'}};
1454 }
1455  
1456 # handle inheritance
1457 266 ▶ unless ($class_name eq "UR::Object") {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class_name eq "UR::Object") 266 0 266
1458 266 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1459  
1460 # sanity check
1461 266 my @expected = @$inheritance;
1462 266 my @actual = @{ $class_name . "::ISA" };
1463  
1464 266 ▶ if (@actual and "@actual" ne "@expected") {
Branch: 1 branch
BranchTrueFalseTotal
if (@actual and join($", @actual) ne join($", @expected)) 0 266 266
Condition33%1/3
@actual and join($", @actual) ne join($", @expected)
!ll&&!rl&&r
02660
MC/DC0%0/2
@actual and join($", @actual) ne join($", @expected)
@actual join($", @actual) ne join($", @expected)
Truth table33%1/3
A and B
A= @actualB= join($", @actual) ne join($", @expected)
ABresult
0X0
100
111
1465 0 Carp::confess("for $class_name: expected '@expected' actual '@actual'\n");
1466 }
1467  
1468 # set
1469 266 @{ $class_name . "::ISA" } = @$inheritance;
1470 }
1471  
1472 266 ▶ if (not $data_source and $class_name->can("__load__")) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $data_source and $class_name->can("__load__")) 0 266 266
Condition33%1/3
not $data_source and $class_name->can("__load__")
!ll&&!rl&&r
02660
MC/DC0%0/2
not $data_source and $class_name->can("__load__")
not $data_source $class_name->can("__load__")
Truth table33%1/3
not(A) and B
A= not $data_sourceB= $class_name->can("__load__")
ABresult
0X0
100
111
1473 # $data_source = UR::DataSource::Default->__define__;
1474 0 $data_source = $self->{data_source_id} = $self->{db_committed}->{data_source_id} = 'UR::DataSource::Default';
1475 }
1476  
1477 # Create inline data source
1478 266 ▶ if ($data_source and ref($data_source) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($data_source and ref $data_source eq "HASH") 0 266 266
Condition33%1/3
$data_source and ref $data_source eq "HASH"
!ll&&!rl&&r
26600
MC/DC0%0/2
$data_source and ref $data_source eq "HASH"
$data_source ref $data_source eq "HASH"
Truth table33%1/3
A and B
A= $data_sourceB= ref $data_source eq "HASH"
ABresult
0X0
100
111
1479 0 $self->{'__inline_data_source_data'} = $data_source;
1480 0 my $ds_class = $data_source->{'is'};
1481 0 my $inline_ds = $ds_class->create_from_inline_class_data($self, $data_source);
1482 0 $self->{'data_source_id'} = $self->{'db_committed'}->{'data_source_id'} = $inline_ds->id;
1483 }
1484  
1485
1486 266 ▶ if ($self->{'data_source_id'} and !defined($self->{table_name})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"data_source_id"} and not defined $self->{"table_name"}) 0 266 266
Condition33%1/3
$self->{"data_source_id"} and not defined $self->{"table_name"}
!ll&&!rl&&r
26600
MC/DC0%0/2
$self->{"data_source_id"} and not defined $self->{"table_name"}
$self->{"data_source_id"} not defined $self->{"table_name"}
Truth table33%1/3
A and not(B)
A= $self->{"data_source_id"}B= not defined $self->{"table_name"}
ABresult
0X0
100
111
1487 0 ▶ my $data_source_obj = UR::DataSource->get($self->{'data_source_id'}) || eval { $self->{'data_source_id'}->get() };
Condition0%0/3
'UR::DataSource'->get($self->{'data_source_id'}) || eval { do { $self->{'data_source_id'}->get } }
l!l&&r!l&&!r
000
MC/DC0%0/2
'UR::DataSource'->get($self->{'data_source_id'}) || eval { do { $self->{'data_source_id'}->get } }
'UR::DataSource'->get($self->{'data_source_id'}) eval { do { $self->{'data_source_id'}->get } }
Truth table0%0/3
A || B
A= 'UR::DataSource'->get($self->{'data_source_id'})B= eval { do { $self->{'data_source_id'}->get } }
ABresult
1X1
011
000
1488 0 ▶ if ($data_source_obj and $data_source_obj->initializer_should_create_column_name_for_class_properties() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data_source_obj and $data_source_obj->initializer_should_create_column_name_for_class_properties) 0 0 0
Condition0%0/3
$data_source_obj and $data_source_obj->initializer_should_create_column_name_for_class_properties
!ll&&!rl&&r
000
MC/DC0%0/2
$data_source_obj and $data_source_obj->initializer_should_create_column_name_for_class_properties
$data_source_obj $data_source_obj->initializer_should_create_column_name_for_class_properties
Truth table0%0/3
A and B
A= $data_source_objB= $data_source_obj->initializer_should_create_column_name_for_class_properties
ABresult
0X0
100
111
1489 0 $self->{table_name} = '__default__';
1490 }
1491 }
1492  
1493 266 for my $parent_class_name (@$inheritance) {
1494 266 my $parent_class = $parent_class_name->__meta__;
1495 266 ▶ unless ($parent_class) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($parent_class) 0 266 266
1496 #$DB::single = 1;
1497 0 $parent_class = $parent_class_name->__meta__;
1498 0 $self->error_message("Failed to find parent class $parent_class_name\n");
1499 0 return;
1500 }
1501  
1502 # These class meta values get propogated from parent to child
1503 266 foreach my $inh_property ( qw(schema_name data_source_id) ) {
1504 532 ▶ if (not defined ($self->$inh_property)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->$inh_property) 532 0 532
1505 532 ▶ if (my $inh_value = $parent_class->$inh_property) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $inh_value = $parent_class->$inh_property) 0 532 532
1506 0 $self->{$inh_property} = $self->{'db_committed'}->{$inh_property} = $inh_value;
1507 }
1508 }
1509 }
1510  
1511 # For classes with no data source, the default for id_generator is -urinternal
1512 # For classes with a data source, autogenerate_new_object_id_for_class_name_and_rule gets called
1513 # on that data source which can use id_generator as it sees fit
1514 266 ▶ if (! defined $self->{id_generator}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"id_generator"}) 266 0 266
1515 266 my $id_generator;
1516 266 ▶ if ($self->{data_source_id}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'data_source_id'}) { } 0 266 266
1517 0 ▶ if ($parent_class->data_source_id
Branch: 1 branch
BranchTrueFalseTotal
if ($parent_class->data_source_id and $parent_class->data_source_id eq $self->data_source_id) 0 0 0
Condition0%0/3
$parent_class->data_source_id and $parent_class->data_source_id eq $self->data_source_id
!ll&&!rl&&r
000
MC/DC0%0/2
$parent_class->data_source_id and $parent_class->data_source_id eq $self->data_source_id
$parent_class->data_source_id $parent_class->data_source_id eq $self->data_source_id
Truth table0%0/3
A and B
A= $parent_class->data_source_idB= $parent_class->data_source_id eq $self->data_source_id
ABresult
0X0
100
111
1518 and
1519 $parent_class->data_source_id eq $self->data_source_id
1520 ) {
1521 0 $id_generator = $parent_class->id_generator;
1522 }
1523 } else {
1524 266 $id_generator = $parent_class->id_generator;
1525 }
1526 266 $self->{id_generator} = $self->{'db_committed'}->{id_generator} = $id_generator;
1527 }
1528  
1529  
1530 # If a parent is declared as a singleton, we are too.
1531 # This only works for abstract singletons.
1532 266 ▶ if ($parent_class->is_singleton and not $self->is_singleton) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent_class->is_singleton and not $self->is_singleton) 0 266 266
Condition33%1/3
$parent_class->is_singleton and not $self->is_singleton
!ll&&!rl&&r
26600
MC/DC0%0/2
$parent_class->is_singleton and not $self->is_singleton
$parent_class->is_singleton not $self->is_singleton
Truth table33%1/3
A and not(B)
A= $parent_class->is_singletonB= not $self->is_singleton
ABresult
0X0
100
111
1533 0 $self->is_singleton($parent_class->is_singleton);
1534 }
1535 }
1536  
1537 # when we "have" an object reference, add it to the list of old-style references
1538 # also ensure the old-style property definition is complete
1539 0 for my $pinfo (grep { $_->{id_by} } values %$properties) {
1540 0 push @$relationships, $pinfo->{property_name}, $pinfo;
1541  
1542 0 my $id_properties = $pinfo->{id_by};
1543 0 my $r_class_name = $pinfo->{data_type};
1544 0 ▶ unless($r_class_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r_class_name) 0 0 0
1545 die sprintf("Object accessor property definition for %s::%s has an 'id_by' but no 'data_type'",
1546 0 $pinfo->{'class_name'}, $pinfo->{'property_name'});
1547 }
1548 0 my $r_class;
1549 my @r_id_properties;
1550  
1551 0 ▶ for (my $n=0; $n<@$id_properties; $n++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n < @$id_properties) 0 0 0
1552 0 my $id_property_name = $id_properties->[$n];
1553 0 my $id_property_detail = $properties->{$id_property_name};
1554 0 ▶ unless ($id_property_detail) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($id_property_detail) 0 0 0
1555 #$DB::single = 1;
1556 0 1;
1557 }
1558  
1559 # No data_type specified, first try parent classes for the same property name
1560 # and use their type
1561 0 ▶ if (!$bootstrapping and !exists($id_property_detail->{data_type})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($UR::Object::Type::bootstrapping or exists $id_property_detail->{"data_type"}) 0 0 0
Condition0%0/3
$UR::Object::Type::bootstrapping or exists $id_property_detail->{"data_type"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$UR::Object::Type::bootstrapping or exists $id_property_detail->{"data_type"}
$UR::Object::Type::bootstrapping exists $id_property_detail->{"data_type"}
Truth table0%0/3
A or B
A= $UR::Object::Type::bootstrappingB= exists $id_property_detail->{"data_type"}
ABresult
1X1
011
000
1562 0 ▶ if (my $inh_prop = ($self->ancestry_property_metas(property_name => $id_property_name))[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $inh_prop = ($self->ancestry_property_metas("property_name", $id_property_name))[0]) 0 0 0
1563 0 $id_property_detail->{data_type} = $inh_prop->data_type;
1564 }
1565 }
1566  
1567 # Didn't find one - use the data type of the ID property(s) in the class we point to
1568 0 ▶ unless ($id_property_detail->{data_type}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($id_property_detail->{"data_type"}) 0 0 0
1569 0 ▶ unless ($r_class) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r_class) 0 0 0
1570 # FIXME - it'd be nice if we didn't have to load the remote class here, and
1571 # instead put off loading until it's necessary
1572 0 ▶ $r_class ||= UR::Object::Type->get($r_class_name);
Condition0%0/3
$r_class ||= "UR::Object::Type"->get($r_class_name)
l!l&&r!l&&!r
000
MC/DC0%0/2
$r_class ||= "UR::Object::Type"->get($r_class_name)
$r_class "UR::Object::Type"->get($r_class_name)
Truth table0%0/3
A ||= B
A= $r_classB= "UR::Object::Type"->get($r_class_name)
ABresult
1X1
011
000
1573 0 ▶ unless ($r_class) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r_class) 0 0 0
1574 0 Carp::confess("Unable to load $r_class_name while defining relationship ".$pinfo->{'property_name'}. " in class $class_name");
1575 }
1576 0 @r_id_properties = $r_class->id_property_names;
1577 }
1578 my ($r_property) =
1579 map {
1580 0 my $r_class_ancestor = UR::Object::Type->get($_);
1581 0 my $data = $r_class_ancestor->{has}{$r_id_properties[$n]};
1582 0 ▶ ($data ? ($data) : ());
Branch: 1 branch
BranchTrueFalseTotal
$data ? : 0 0 0
1583 }
1584 ($r_class_name, $r_class_name->__meta__->ancestry_class_names);
1585 0 ▶ unless ($r_property) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r_property) 0 0 0
1586 #$DB::single = 1;
1587 0 my $property_name = $pinfo->{'property_name'};
1588 0 ▶ if (@$id_properties != @r_id_properties) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$id_properties != @r_id_properties) { } 0 0 0
1589 0 Carp::croak("Can't resolve relationship for class $class_name property '$property_name': "
1590 . "id_by metadata has " . scalar(@$id_properties) . " items, but remote class "
1591 . "$r_class_name only has " . scalar(@r_id_properties) . " ID properties\n");
1592 } else {
1593 0 ▶ my $r_id_property = $r_id_properties[$n] ? "'$r_id_properties[$n]'" : '(undef)';
Branch: 1 branch
BranchTrueFalseTotal
$r_id_properties[$n] ? : 0 0 0
1594 0 Carp::croak("Can't resolve relationship for class $class_name property '$property_name': "
1595 . "Class $r_class_name does not have an ID property named $r_id_property, "
1596 . "which would be linked to the local property '".$id_properties->[$n]."'\n");
1597 }
1598 }
1599 0 $id_property_detail->{data_type} = $r_property->{data_type};
1600 }
1601 }
1602 0 next;
1603 }
1604  
1605 # make old-style (bc4nf) property objects in the default way
1606 266 my %property_objects;
1607  
1608 266 for my $pinfo (values %$properties) {
1609 0 my $property_name = $pinfo->{property_name};
1610 0 my $property_subclass = $pinfo->{property_subclass};
1611  
1612 # Acme::Employee::Attribute::Name is a bc6nf attribute
1613 # extends Acme::Employee::Attribute
1614 # extends UR::Object::Attribute
1615 # extends UR::Object
1616 0 my @words = map { ucfirst($_) } split(/_/,$property_name);
1617 #@words = $self->namespace->get_vocabulary->convert_to_title_case(@words);
1618 0 my $bridge_class_name =
1619 $class_name
1620 . "::Attribute::"
1621 . join('', @words);
1622  
1623 # Acme::Employee::Attribute::Name::Type is both the class definition for the bridge,
1624 # and also the attribute/property metadata for
1625 0 my $property_meta_class_name = $bridge_class_name . "::Type";
1626  
1627 # define a new class for the above, inheriting from UR::Object::Property
1628 # all of the "attributes_have" get put into the class definition
1629 # call the constructor below on that new class
1630 #UR::Object::Type->__define__(
1631 ## class_name => $property_meta_class_name,
1632 # is => 'UR::Object::Property', # TODO: go through the inheritance
1633 # has => [
1634 # @{ $class_name->__meta__->{attributes_have} }
1635 # ]
1636 #)
1637  
1638 0 my ($singular_name,$plural_name);
1639 0 ▶ unless ($pinfo->{plural_name} and $pinfo->{singular_name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pinfo->{"plural_name"} and $pinfo->{"singular_name"}) 0 0 0
Condition0%0/3
$pinfo->{"plural_name"} and $pinfo->{"singular_name"}
!ll&&!rl&&r
000
MC/DC0%0/2
$pinfo->{"plural_name"} and $pinfo->{"singular_name"}
$pinfo->{"plural_name"} $pinfo->{"singular_name"}
Truth table0%0/3
A and B
A= $pinfo->{"plural_name"}B= $pinfo->{"singular_name"}
ABresult
0X0
100
111
1640 0 require Lingua::EN::Inflect;
1641 0 ▶ if ($pinfo->{is_many}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pinfo->{'is_many'}) { } 0 0 0
1642 0 ▶ $plural_name = $pinfo->{plural_name} ||= $pinfo->{property_name};
Condition0%0/3
$pinfo->{"plural_name"} ||= $pinfo->{"property_name"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$pinfo->{"plural_name"} ||= $pinfo->{"property_name"}
$pinfo->{"plural_name"} $pinfo->{"property_name"}
Truth table0%0/3
A ||= B
A= $pinfo->{"plural_name"}B= $pinfo->{"property_name"}
ABresult
1X1
011
000
1643 0 $pinfo->{singular_name} = Lingua::EN::Inflect::PL_V($plural_name);
1644 }
1645 else {
1646 0 ▶ $singular_name = $pinfo->{singular_name} ||= $pinfo->{property_name};
Condition0%0/3
$pinfo->{"singular_name"} ||= $pinfo->{"property_name"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$pinfo->{"singular_name"} ||= $pinfo->{"property_name"}
$pinfo->{"singular_name"} $pinfo->{"property_name"}
Truth table0%0/3
A ||= B
A= $pinfo->{"singular_name"}B= $pinfo->{"property_name"}
ABresult
1X1
011
000
1647 0 $pinfo->{plural_name} = Lingua::EN::Inflect::PL($singular_name);
1648 }
1649 }
1650  
1651 0 my $property_object = UR::Object::Property->__define__(%$pinfo, id => $class_name . "\t" . $property_name);
1652  
1653 0 ▶ unless ($property_object) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($property_object) 0 0 0
1654 0 $self->error_message("Error creating property $property_name for class " . $self->class_name . ": " . $class_name->error_message);
1655 0 for $property_object (@subordinate_objects) { $property_object->unload }
1656 0 $self->unload;
1657 0 return;
1658 }
1659  
1660 0 $property_objects{$property_name} = $property_object;
1661 0 push @subordinate_objects, $property_object;
1662 }
1663  
1664 266 ▶ if ($constraints) {
Branch: 1 branch
BranchTrueFalseTotal
if ($constraints) 266 0 266
1665 266 my $property_rule_template = UR::BoolExpr::Template->resolve('UR::Object::Property','class_name','property_name');
1666  
1667 266 my $n = 1;
1668 0 for my $unique_set (sort { $a->{sql} cmp $b->{sql} } @$constraints) {
1669 0 my ($name,$properties,$group,$sql);
1670 0 ▶ if (ref($unique_set) eq "HASH") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $unique_set eq 'HASH') { } 0 0 0
1671 0 $name = $unique_set->{name};
1672 0 $properties = $unique_set->{properties};
1673 0 $sql = $unique_set->{sql};
1674 0 ▶ $name ||= $sql;
Condition0%0/3
$name ||= $sql
l!l&&r!l&&!r
000
MC/DC0%0/2
$name ||= $sql
$name $sql
Truth table0%0/3
A ||= B
A= $nameB= $sql
ABresult
1X1
011
000
1675 }
1676 else {
1677 0 $properties = @$unique_set;
1678 0 $name = '(unnamed)';
1679 0 $n++;
1680 }
1681 0 for my $property_name (sort @$properties) {
1682 0 my $prop_rule = $property_rule_template->get_rule_for_values($class_name,$property_name);
1683 0 my $property = $UR::Context::current->get_objects_for_class_and_rule('UR::Object::Property', $prop_rule);
1684 0 ▶ unless ($property) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($property) 0 0 0
1685 0 Carp::croak("Constraint '$name' on class $class_name requires unknown property '$property_name'");
1686 }
1687 }
1688 }
1689 }
1690  
1691 266 for my $obj ($self,@subordinate_objects) {
1692 #use Data::Dumper;
1693 266 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1694 266 my %db_committed = %$obj;
1695 266 delete @db_committed{@keys_to_delete_from_db_committed};
1696 266 $obj->{'db_committed'} = \%db_committed;
1697  
1698 };
1699  
1700 266 ▶ unless ($self->generate) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->generate) 0 0 0
1701 0 $self->error_message("Error generating class " . $self->class_name . " as part of creation : " . $self->error_message);
1702 0 for my $property_object (@subordinate_objects) { $property_object->unload }
1703 0 $self->unload;
1704 0 return;
1705 }
1706  
1707 0 ▶ if (my $extra = $self->{extra}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $extra = $self->{"extra"}) 0 0 0
1708 0 $self->_apply_extra_attrs_to_class_or_role($extra);
1709 }
1710  
1711 0 $self->__signal_change__("load");
1712  
1713  
1714 0 my @i = $class_name->inheritance;
1715  
1716 0 for my $parent_class_name (@i) {
1717 0 ▶ if ($parent_class_name->can('__signal_observers__')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent_class_name->can("__signal_observers__")) 0 0 0
1718 0 $parent_class_name->__signal_observers__('subclass_loaded', $class_name);
1719 }
1720 }
1721  
1722 # The inheritance method is high overhead because of the number of times it is called.
1723 # Cache on a per-class basis.
1724 0 ▶ if (grep { $_ eq '' } @i) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "";} @i) 0 0 0
1725 0 print "$class_name! @{ $self->{is} }";
1726 0 $class_name->inheritance;
1727 }
1728 0 ▶ Carp::confess("Odd inheritance @i for $class_name") unless $class_name->isa('UR::Object');
Branch: 1 branch
BranchTrueFalseTotal
unless $class_name->isa("UR::Object") 0 0 0
1729 0 my $src1 = " return shift->SUPER::inheritance(\@_) if ( (ref(\$_[0])||\$_[0]) ne '$class_name'); return (" . join(", ", map { "'$_'" } (@i)) . ")";
1730 0 my $src2 = qq|sub ${class_name}::inheritance { $src1 }|;
1731 0 ▶ eval $src2 unless $class_name eq 'UR::Object';
Branch: 1 branch
BranchTrueFalseTotal
unless $class_name eq "UR::Object" 0 0 0
1732 0 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
1733  
1734 0 $self->{'_property_meta_for_name'} = \%property_objects;
1735  
1736 # return the new class object
1737 0 return $self;
1738 }
1739  
1740 0 ▶sub _apply_extra_attrs_to_class_or_role {
Subroutine _apply_extra_attrs_to_class_or_role: not called CC=6 SCAR=37.4
1741 0 my($self, $extra) = @_;
1742  
1743 0 ▶ if ($extra) {
Branch: 1 branch
BranchTrueFalseTotal
if ($extra) 0 0 0
1744 # some class characteristics may be only present in subclasses of UR::Object
1745 # we handle these at this point, since the above is needed for bootstrapping
1746 0 my %still_not_found;
1747 0 for my $key (sort keys %$extra) {
1748 0 ▶ if ($self->can($key)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can($key)) { } 0 0 0
1749 0 $self->$key($extra->{$key});
1750 }
1751 else {
1752 0 $still_not_found{$key} = $extra->{$key};
1753 }
1754 }
1755 0 ▶ if (%still_not_found) {
Branch: 1 branch
BranchTrueFalseTotal
if (%still_not_found) 0 0 0
1756 0 ▶ my $kind = $self->isa('UR::Object::Type')
Branch: 1 branch
BranchTrueFalseTotal
$self->isa('UR::Object::Type') ? : 0 0 0
1757 ? 'Class'
1758 : 'Role';
1759 0 my $name = $self->id;
1760  
1761 0 $DB::single = 1;
1762 Carp::croak("Bad $kind defninition for $name. Unrecognized properties:\n\t"
1763 0 . join("\n\t", join(' => ', map { ($_, $still_not_found{$_}) } keys %still_not_found)));
1764 }
1765 }
1766  
1767  
1768 }
1769  
1770 # write the module from the existing data in the class object
1771 266 ▶sub generate {
Subroutine generate: called CC=28 SCAR=59.5
Pod undocumented
1772 266 my $self = shift;
1773 266 ▶ return 1 if $self->{'generated'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"generated"} 0 266 266
1774  
1775 #my %params = @_; # Doesn't seem to be used below...
1776  
1777  
1778 # The follwing code will override a lot intentionally.
1779 # Supress the warning messages.
1780 266 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1781  
1782 # the class that this object represents
1783 # the class that we're going to generate
1784 # the "new class"
1785 266 my $class_name = $self->class_name;
1786  
1787 # this is done earlier in the class definition process in _make_minimal_class_from_normalized_class_description()
1788 266 my $full_name = join( '::', $class_name, '__meta__' );
1789 Sub::Install::reinstall_sub({
1790 into => $class_name,
1791 as => '__meta__',
1792 0 ▶ code => Sub::Name::subname $full_name => sub {$self},
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __meta__: not called CC=1 SCAR=6.9
1793 266 });
1794  
1795 266 my @parent_class_names = $self->parent_class_names;
1796  
1797 266 do {
1798 266 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1799 266 ▶ if (@{ $class_name . '::ISA' }) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$class_name . '::ISA';}) { } 266 0 266
1800 #print "already have isa for class_name $class_name: " . join(",",@{ $class_name . '::ISA' }) . "\n";
1801 }
1802 else {
1803 266 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1804 0 @{ $class_name . '::ISA' } = @parent_class_names;
1805 #print "setting isa for class_name $class_name: " . join(",",@{ $class_name . '::ISA' }) . "\n";
1806 };
1807 };
1808  
1809  
1810 266 my ($props, $cols) = ([], []); # for _all_properties_columns()
1811 266 $self->{_all_properties_columns} = [$props, $cols];
1812  
1813 266 my $id_props = []; # for _all_id_properties()
1814 266 $self->{_all_id_properties} = $id_props;
1815  
1816 # build the supplemental classes
1817 266 for my $parent_class_name (@parent_class_names) {
1818 266 ▶ next if $parent_class_name eq "UR::Object";
Branch: 1 branch
BranchTrueFalseTotal
if $parent_class_name eq "UR::Object" 0 266 266
1819  
1820 266 ▶ if ($parent_class_name eq $class_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent_class_name eq $class_name) 0 266 266
1821 0 Carp::confess("$class_name has parent class list which includes itself?: @parent_class_names\n");
1822 }
1823  
1824 266 my $parent_class_meta = UR::Object::Type->get(class_name => $parent_class_name);
1825  
1826 0 ▶ unless ($parent_class_meta) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($parent_class_meta) 0 0 0
1827 #$DB::single = 1;
1828 0 $parent_class_meta = UR::Object::Type->get(class_name => $parent_class_name);
1829 0 Carp::confess("Cannot generate $class_name: Failed to find class meta-data for base class $parent_class_name.");
1830 }
1831  
1832 0 ▶ unless ($parent_class_meta->generated()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($parent_class_meta->generated) 0 0 0
1833 0 $parent_class_meta->generate();
1834 }
1835  
1836 0 ▶ unless ($parent_class_meta->{_all_properties_columns}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($parent_class_meta->{"_all_properties_columns"}) 0 0 0
1837 0 Carp::confess("No _all_properties_columns for $parent_class_name?");
1838 }
1839  
1840 # inherit properties and columns
1841 0 my ($p, $c) = @{ $parent_class_meta->{_all_properties_columns} };
1842 0 ▶ push @$props, @$p if $p;
Branch: 1 branch
BranchTrueFalseTotal
if $p 0 0 0
1843 0 ▶ push @$cols, @$c if $c;
Branch: 1 branch
BranchTrueFalseTotal
if $c 0 0 0
1844 0 my $id_p = $parent_class_meta->{_all_id_properties};
1845 0 ▶ push @$id_props, @$id_p if $id_p;
Branch: 1 branch
BranchTrueFalseTotal
if $id_p 0 0 0
1846 }
1847  
1848  
1849 # set up accessors/mutators for properties
1850 0 my @property_objects =
1851 UR::Object::Property->get(class_name => $self->class_name);
1852  
1853 0 my @id_property_objects = $self->direct_id_property_metas;
1854 0 my %id_property;
1855 0 for my $ipo (@id_property_objects) {
1856 0 $id_property{$ipo->property_name} = 1;
1857 }
1858  
1859 0 ▶ if (@id_property_objects) {
Branch: 1 branch
BranchTrueFalseTotal
if (@id_property_objects) 0 0 0
1860 0 $id_props = [];
1861 0 for my $ipo (@id_property_objects) {
1862 0 push @$id_props, $ipo->property_name;
1863 }
1864 }
1865  
1866 0 my $has_table;
1867 0 my @parent_classes = map { UR::Object::Type->get(class_name => $_) } @parent_class_names;
1868 0 for my $co ($self, @parent_classes) {
1869 0 ▶ if ($co->table_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($co->table_name) 0 0 0
1870 0 $has_table = 1;
1871 0 last;
1872 }
1873 }
1874  
1875 0 my $data_source_obj = $self->data_source;
1876 0 my $columns_are_upper_case;
1877 0 ▶ if ($data_source_obj) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data_source_obj) 0 0 0
1878 0 $columns_are_upper_case = $data_source_obj->table_and_column_names_are_upper_case;
1879 }
1880  
1881 0 my @sort_list = map { [$_->property_name, $_] } @property_objects;
1882 0 for my $sorted_item ( sort { $a->[0] cmp $b->[0] } @sort_list ) {
1883 0 my $property_object = $sorted_item->[1];
1884 0 ▶ if ($property_object->column_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($property_object->column_name) 0 0 0
1885 0 push @$props, $property_object->property_name;
1886 0 ▶ push @$cols, $columns_are_upper_case ? uc($property_object->column_name) : $property_object->column_name;
Branch: 1 branch
BranchTrueFalseTotal
$columns_are_upper_case ? : 0 0 0
1887 }
1888 }
1889  
1890 # set the flag to prevent this from occurring multiple times.
1891 0 $self->generated(1);
1892  
1893 # read in filesystem package if there is one
1894 #$self->use_filesystem_package($class_name);
1895  
1896 # Let each class in the inheritance hierarchy do any initialization
1897 # required for this class. Note that the _init_subclass method does
1898 # not call SUPER::, but relies on this code to find its parents. This
1899 # is the only way around a sparsely-filled multiple inheritance tree.
1900  
1901 # TODO: Replace with $class_name->EVERY::LAST::_init_subclass()
1902  
1903 #unless (
1904 # $bootstrapping
1905 # and
1906 # $UR::Object::_init_subclass->{$class_name}
1907 #)
1908 {
1909 0 my @inheritance = $class_name->inheritance;
1910 0 my %done;
1911 0 for my $parent (reverse @inheritance) {
1912 0 my $initializer = $parent->can("_init_subclass");
1913 0 ▶ next unless $initializer;
Branch: 1 branch
BranchTrueFalseTotal
unless $initializer 0 0 0
1914 0 ▶ next if $done{$initializer};
Branch: 1 branch
BranchTrueFalseTotal
if $done{$initializer} 0 0 0
1915 0 ▶ $initializer->($class_name,$class_name)
Branch: 1 branch
BranchTrueFalseTotal
&$initializer($class_name, $class_name) or die "Parent class $parent failed to initialize subclass " . "$class_name :" . $parent->error_message 0 0 0
1916 or die "Parent class $parent failed to initialize subclass "
1917 . "$class_name :" . $parent->error_message;
1918 0 $done{$initializer} = 1;
1919 }
1920 }
1921  
1922 0 ▶ unless ($class_name->isa("UR::Object")) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class_name->isa("UR::Object")) 0 0 0
1923 0 print Data::Dumper::Dumper('@C::ISA',\@C::ISA,'@B::ISA',\@B::ISA);
1924 }
1925  
1926 # ensure the class is generated
1927 0 ▶ die "Error in module for $class_name. Resulting class does not appear to be generated!" unless $self->generated;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->generated 0 0 0
1928  
1929 # ensure the class inherits from UR::Object
1930 0 ▶ die "$class_name does not inherit from UR::Object!" unless $class_name->isa("UR::Object");
Branch: 1 branch
BranchTrueFalseTotal
unless $class_name->isa("UR::Object") 0 0 0
1931  
1932 0 return 1;
1933 }
1934  
1935  
1936 143 1;
1937  
1938  
« blib/lib/UR/DataSource/RDBMS.pm ↑ Summary blib/lib/UR/Change.pm »