| 1 | package UR::Object::Type; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 266 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 266 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 266 | require UR; | |||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | # Used during bootstrapping. | ||||||||||||||||||||||||||||||||||||||||||
| 8 | 266 | our @ISA = qw(UR::Object); | |||||||||||||||||||||||||||||||||||||||||
| 9 | 266 | our $VERSION = "0.47"; # UR $VERSION; | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 266 | our @CARP_NOT = qw( UR::Object UR::Context UR::ModuleLoader Class::Autouse UR::BoolExpr ); | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | # Most of the API for this module are legacy internals required by UR. | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 266 | ▶ | use UR::Object::Type::InternalAPI; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | # This module implements define(), and most everything behind it. | ||||||||||||||||||||||||||||||||||||||||||
| 17 | 266 | ▶ | use UR::Object::Type::Initializer; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | # The methods used by the initializer to write accessors in perl. | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 266 | ▶ | use UR::Object::Type::AccessorWriter; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | # The methods to extract/(re)create definition text in the module source file. | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 266 | ▶ | use UR::Object::Type::ModuleWriter; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | # Present the internal definer as an external method | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 6382 | ▶ | sub define { shift->__define__(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
define: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | # For efficiency, certain hash keys inside the class cache property metadata | ||||||||||||||||||||||||||||||||||||||||||
| 29 | # These go in this array, and are cleared when property metadata is mutated | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 266 | our @cache_keys; | |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | # This is the function behind $class_meta->properties(...) | ||||||||||||||||||||||||||||||||||||||||||
| 33 | # It mimics the has-many object accessor, but handles inheritance | ||||||||||||||||||||||||||||||||||||||||||
| 34 | # Once we have "isa" and "is-parent-of" operator we can do this with regular operators. | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 266 | push @cache_keys, '_properties'; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | sub _properties { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_properties: not called CC=15 SCAR=53.4
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | my $all = $self->{_properties} ||= do { | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"_properties"} ||= do {
my $map = $self->_property_name_class_map;
my @all;
foreach my $property_name (sort keys %$map) {
my $class_names = $map->{$property_name};
my $class_name = $class_names->[0];
my $id = $class_name . "\t" . $property_name;
my $property_meta = "UR::Object::Property"->get($id);
unless ($property_meta) {
Carp::confess("Failed to find property meta for $class_name $property_name?");
};
push @all, $property_meta;
};
\@all
}
MC/DC0%0/2
$self->{"_properties"} ||= do {
my $map = $self->_property_name_class_map;
my @all;
foreach my $property_name (sort keys %$map) {
my $class_names = $map->{$property_name};
my $class_name = $class_names->[0];
my $id = $class_name . "\t" . $property_name;
my $property_meta = "UR::Object::Property"->get($id);
unless ($property_meta) {
Carp::confess("Failed to find property meta for $class_name $property_name?");
};
push @all, $property_meta;
};
\@all
}
$self->{"_properties"}
do {
my $map = $self->_property_name_class_map;
my @all;
foreach my $property_name (sort keys %$map) {
my $class_names = $map->{$property_name};
my $class_name = $class_names->[0];
my $id = $class_name . "\t" . $property_name;
my $property_meta = "UR::Object::Property"->get($id);
unless ($property_meta) {
Carp::confess("Failed to find property meta for $class_name $property_name?");
};
push @all, $property_meta;
};
\@all
}
Truth table0%0/3
A ||= B
A= $self->{"_properties"}B= do {
my $map = $self->_property_name_class_map;
my @all;
foreach my $property_name (sort keys %$map) {
my $class_names = $map->{$property_name};
my $class_name = $class_names->[0];
my $id = $class_name . "\t" . $property_name;
my $property_meta = "UR::Object::Property"->get($id);
unless ($property_meta) {
Carp::confess("Failed to find property meta for $class_name $property_name?");
};
push @all, $property_meta;
};
\@all
}
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | # start with everything, as it's a small list | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my $map = $self->_property_name_class_map; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | my @all; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | for my $property_name (sort keys %$map) { | |||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | my $class_names = $map->{$property_name}; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | my $class_name = $class_names->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | my $id = $class_name . "\t" . $property_name; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | my $property_meta = UR::Object::Property->get($id); | |||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | unless ($property_meta) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | Carp::confess("Failed to find property meta for $class_name $property_name?"); | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | push @all, $property_meta; | |||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | \@all; | |||||||||||||||||||||||||||||||||||||||||
| 53 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my ($bx, %extra) = UR::Object::Property->define_boolexpr(@_); | |||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | my @matches = grep { $bx->evaluate($_) } @$all; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if (%extra) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | # Additional meta-properties on meta-properties are not queryable until we | ||||||||||||||||||||||||||||||||||||||||||
| 59 | # put the UR::Object::Property into a private sub-class. | ||||||||||||||||||||||||||||||||||||||||||
| 60 | # This will give us most of the functionality. | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | for my $key (keys %extra) { | |||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my ($name,$op) = ($key =~ /(\w+)\s*(.*)/); | |||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | unless (defined $self->{attributes_have}->{$name}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | die "unknown property $name used to query properties of " . $self->class_name; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if ($op and $op ne '==' and $op ne 'eq') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$op and $op ne "==" and $op ne "eq"
$op and $op ne "=="
MC/DC0%0/3
$op and $op ne "==" and $op ne "eq"
$op
$op ne "=="
$op ne "eq"
Truth table0%0/4
A and B and C
A= $opB= $op ne "=="C= $op ne "eq"
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | die "operations besides equals are not supported currently for added meta-properties like $name on class " . $self->class_name; | |||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | my $value = $extra{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 266 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | @matches = grep { $_->can($name) and $_->$name eq $value } @matches; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$_->can($name) && $_->$name eq $value
MC/DC0%0/2
$_->can($name) && $_->$name eq $value
$_->can($name)
$_->$name eq $value
Truth table0%0/3
A && B
A= $_->can($name)B= $_->$name eq $value
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | return if not defined wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | return @matches if wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | die "Matched multiple meta-properties, but called in scalar context!" . Data::Dumper::Dumper(\@matches) if @matches > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | return $matches[0]; | |||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | @$all; | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | sub property { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
property: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if (@_ == 2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | # optimize for the common case | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | my ($self, $property_name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | my $class_names = $self->_property_name_class_map->{$property_name}; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | return unless $class_names and @$class_names; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$class_names and @$class_names
MC/DC0%0/2
$class_names and @$class_names
$class_names
@$class_names
Truth table0%0/3
A and B
A= $class_namesB= @$class_names
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | my $id = $class_names->[0] . "\t" . $property_name; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | return UR::Object::Property->get($id); | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 94 | # this forces scalar context, raising an exception if | ||||||||||||||||||||||||||||||||||||||||||
| 95 | # the params used result in more than one match | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | my $one = shift->properties(@_); | |||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | return $one; | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 266 | push @cache_keys, '_property_names'; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub property_names { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
property_names: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my $self = $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | my $names = $self->{_property_names} ||= do { | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"_property_names"} ||= do {
my(@names) = sort(keys %{(shift())->_property_name_class_map;});
\@names
}
MC/DC0%0/2
$self->{"_property_names"} ||= do {
my(@names) = sort(keys %{(shift())->_property_name_class_map;});
\@names
}
$self->{"_property_names"}
do {
my(@names) = sort(keys %{(shift())->_property_name_class_map;});
\@names
}
Truth table0%0/3
A ||= B
A= $self->{"_property_names"}B= do {
my(@names) = sort(keys %{(shift())->_property_name_class_map;});
\@names
}
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | my @names = sort keys %{ shift->_property_name_class_map }; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | \@names; | |||||||||||||||||||||||||||||||||||||||||
| 107 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | return @$names; | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 266 | push @cache_keys, '_property_name_class_map'; | |||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | sub _property_name_class_map { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_property_name_class_map: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | my $map = $self->{_property_name_class_map} ||= do { | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"_property_name_class_map"} ||= do {
my(%map) = ();
foreach my $class_name ($self->class_name, $self->ancestry_class_names) {
my $class_meta = "UR::Object::Type"->get($class_name);
if (my $has = $class_meta->{"has"}) {
foreach my $key (sort keys %$has) {
my $classes = ($map{$key} ||= []);
push @$classes, $class_name;
};
};
};
\%map
}
MC/DC0%0/2
$self->{"_property_name_class_map"} ||= do {
my(%map) = ();
foreach my $class_name ($self->class_name, $self->ancestry_class_names) {
my $class_meta = "UR::Object::Type"->get($class_name);
if (my $has = $class_meta->{"has"}) {
foreach my $key (sort keys %$has) {
my $classes = ($map{$key} ||= []);
push @$classes, $class_name;
};
};
};
\%map
}
$self->{"_property_name_class_map"}
do {
my(%map) = ();
foreach my $class_name ($self->class_name, $self->ancestry_class_names) {
my $class_meta = "UR::Object::Type"->get($class_name);
if (my $has = $class_meta->{"has"}) {
foreach my $key (sort keys %$has) {
my $classes = ($map{$key} ||= []);
push @$classes, $class_name;
};
};
};
\%map
}
Truth table0%0/3
A ||= B
A= $self->{"_property_name_class_map"}B= do {
my(%map) = ();
foreach my $class_name ($self->class_name, $self->ancestry_class_names) {
my $class_meta = "UR::Object::Type"->get($class_name);
if (my $has = $class_meta->{"has"}) {
foreach my $key (sort keys %$has) {
my $classes = ($map{$key} ||= []);
push @$classes, $class_name;
};
};
};
\%map
}
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | my %map = (); | |||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | for my $class_name ($self->class_name, $self->ancestry_class_names) { | |||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my $class_meta = UR::Object::Type->get($class_name); | |||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | if (my $has = $class_meta->{has}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | for my $key (sort keys %$has) { | |||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | my $classes = $map{$key} ||= []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$map{$key} ||= []
MC/DC0%0/1
$map{$key} ||= []
$map{$key}
Truth table0%0/2
A
A= $map{$key}
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | push @$classes, $class_name; | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | \%map; | |||||||||||||||||||||||||||||||||||||||||
| 126 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | return $map; | |||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | # The prior implementation of _properties() (behind ->properties()) | ||||||||||||||||||||||||||||||||||||||||||
| 131 | # filtered out certain property meta. This is the old version. | ||||||||||||||||||||||||||||||||||||||||||
| 132 | # The new version above will return one object per property name in | ||||||||||||||||||||||||||||||||||||||||||
| 133 | # the meta ancestry. | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | sub _legacy_properties { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_legacy_properties: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | my $bx = UR::Object::Property->define_boolexpr(@_); | |||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | my @matches = grep { $bx->evaluate($_) } $self->property_metas; | |||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | return if not defined wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | return @matches if wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | die "Matched multiple meta-properties, but called in scalar context!" . Data::Dumper::Dumper(\@matches) if @matches > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | return $matches[0]; | |||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | $self->property_metas; | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 266 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||