| 1 | package UR::Object; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # deprecated parts of the UR::Object API | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 266 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 266 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 266 | require UR; | |||||||||||||||||||||||||||
| 8 | 266 | our $VERSION = "0.47"; # UR $VERSION; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 266 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 266 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 0 | ▶ | sub get_with_special_parameters { | ||||||||||||||||||||||||||
|
Subroutine
get_with_special_parameters: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 14 | # When overridden, this allows a class to take non-properties as parameters | ||||||||||||||||||||||||||||
| 15 | # to get(), and handle loading in a special way. Ideally this is handled by | ||||||||||||||||||||||||||||
| 16 | # a custom data source, or properties with smart definitions. | ||||||||||||||||||||||||||||
| 17 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 18 | 0 | my $rule = shift; | |||||||||||||||||||||||||||
| 19 | 0 | Carp::confess( | |||||||||||||||||||||||||||
| 20 | "Unknown parameters to $class get(). " | ||||||||||||||||||||||||||||
| 21 | . "Implement get_with_special_parameters() to handle non-standard" | ||||||||||||||||||||||||||||
| 22 | . " (non-property) query options.\n" | ||||||||||||||||||||||||||||
| 23 | . "The special params were " | ||||||||||||||||||||||||||||
| 24 | . Dumper(\@_) | ||||||||||||||||||||||||||||
| 25 | . "Rule ID: " . $rule->id . "\n" | ||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | sub get_or_create { | ||||||||||||||||||||||||||
|
Subroutine
get_or_create: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 30 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 31 | 0 | ▶ | return $self->get( @_ ) || $self->create( @_ ); | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->get(@_) || $self->create(@_)
MC/DC0%0/2
$self->get(@_) || $self->create(@_)
$self->get(@_)
$self->create(@_)
Truth table0%0/3
A || B
A= $self->get(@_)B= $self->create(@_)
| |||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | sub set { | ||||||||||||||||||||||||||
|
Subroutine
set: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 35 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 36 | 0 | my @rvals; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | while (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 0 | my $property_name = shift; | |||||||||||||||||||||||||||
| 40 | 0 | my $value = shift; | |||||||||||||||||||||||||||
| 41 | 0 | push(@rvals, $self->$property_name($value)); | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if(wantarray) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 0 | return @rvals; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | else { | ||||||||||||||||||||||||||||
| 48 | 0 | return \@rvals; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | sub property_diff { | ||||||||||||||||||||||||||
|
Subroutine
property_diff: not called CC=6 SCAR=34.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 53 | # Ret hashref of the differences between the object and some other object. | ||||||||||||||||||||||||||||
| 54 | # The "other object" may be a hashref or hash, in which case it will | ||||||||||||||||||||||||||||
| 55 | # treat each key as a property. | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | my ($self, $other) = @_; | |||||||||||||||||||||||||||
| 58 | 0 | my $diff = {}; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | # If we got a hash instead of a hashref... | ||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if (@_ > 2) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | { | ||||||||||||||||||||||||||||
| 63 | 0 | shift; | |||||||||||||||||||||||||||
| 64 | 0 | $other = { @_ } | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 266 | ▶ | no warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 68 | 0 | my $self_value; | |||||||||||||||||||||||||||
| 69 | my $other_value; | ||||||||||||||||||||||||||||
| 70 | 0 | my $class_object = $self->__meta__; | |||||||||||||||||||||||||||
| 71 | 0 | for my $property ($class_object->all_property_names) | |||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||
| 73 | 0 | ▶ | if (ref($other) eq 'HASH') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | { | ||||||||||||||||||||||||||||
| 75 | 0 | ▶ | next unless exists $other->{$property}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 0 | $other_value = $other->{$property}; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | else | ||||||||||||||||||||||||||||
| 79 | { | ||||||||||||||||||||||||||||
| 80 | 0 | $other_value = $other->$property; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | 0 | $self_value = $self->$property; | |||||||||||||||||||||||||||
| 83 | 0 | ▶ | $diff->{$property} = $self_value if ($other_value ne $self_value); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | 0 | return $diff; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | # TODO: make this a context operation | ||||||||||||||||||||||||||||
| 89 | 0 | ▶ | sub unload { | ||||||||||||||||||||||||||
|
Subroutine
unload: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 90 | 0 | my $proto = shift; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | return unless ($proto->class->__meta__->is_uncachable); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | my ($self, $class); | |||||||||||||||||||||||||||
| 95 | 0 | ▶ | ref $proto ? $self = $proto : $class = $proto; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | my $cx = $UR::Context::current; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | if ( $self ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | # object method | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | # The only things which can be unloaded are things committed to | ||||||||||||||||||||||||||||
| 103 | # their database in the exact same state. Everything else must | ||||||||||||||||||||||||||||
| 104 | # be reverted or deleted. | ||||||||||||||||||||||||||||
| 105 | 0 | ▶ | return unless $self->{db_committed}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 0 | ▶ | if ($self->__changes__) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | #warn "NOT UNLOADING CHANGED OBJECT! $self $self->{id}\n"; | ||||||||||||||||||||||||||||
| 108 | 0 | return; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 0 | $self->__signal_change__('unload'); | |||||||||||||||||||||||||||
| 112 | 0 | ▶ | if ($ENV{'UR_DEBUG_OBJECT_RELEASE'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 0 | print STDERR "MEM UNLOAD object $self class ",$self->class," id ",$self->id,"\n"; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | 0 | $cx->_abandon_object($self); | |||||||||||||||||||||||||||
| 116 | 0 | return $self; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | else { | ||||||||||||||||||||||||||||
| 119 | # class method | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | # unload the objects in the class | ||||||||||||||||||||||||||||
| 122 | # where there are subclasses of the class | ||||||||||||||||||||||||||||
| 123 | # delegate to them | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | my @unloaded; | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | # unload all objects of this class | ||||||||||||||||||||||||||||
| 128 | 0 | my @involved_classes = ( $class ); | |||||||||||||||||||||||||||
| 129 | 0 | for my $obj ($cx->all_objects_loaded_unsubclassed($class)) | |||||||||||||||||||||||||||
| 130 | { | ||||||||||||||||||||||||||||
| 131 | 0 | push @unloaded, $obj->unload; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | # unload any objects that belong to any subclasses | ||||||||||||||||||||||||||||
| 135 | 0 | for my $subclass ($cx->__meta__->subclasses_loaded($class)) | |||||||||||||||||||||||||||
| 136 | { | ||||||||||||||||||||||||||||
| 137 | 0 | push @involved_classes, $subclass; | |||||||||||||||||||||||||||
| 138 | 0 | push @unloaded, $subclass->unload; | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | # get rid of the loading info matching this class | ||||||||||||||||||||||||||||
| 142 | 0 | foreach my $template_id ( keys %$UR::Context::all_params_loaded ) { | |||||||||||||||||||||||||||
| 143 | 0 | ▶ | if (UR::BoolExpr::Template->get($template_id)->subject_class_name->isa($class)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | 0 | delete $UR::Context::all_params_loaded->{$template_id}; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | # Turn off the all_objects_are_loaded flags | ||||||||||||||||||||||||||||
| 149 | 0 | delete @$UR::Context::all_objects_are_loaded{@involved_classes}; | |||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 0 | return @unloaded; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | # TODO: replace internal calls to go right to the context method | ||||||||||||||||||||||||||||
| 156 | 266 | ▶ | sub is_loaded { | ||||||||||||||||||||||||||
|
Subroutine
is_loaded: called CC=6 SCAR=28.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 157 | # this is just here for backward compatability for external calls | ||||||||||||||||||||||||||||
| 158 | # get() now goes to the context for data | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | # This shortcut handles the most common case rapidly. | ||||||||||||||||||||||||||||
| 161 | # A single ID is passed-in, and the class name used is | ||||||||||||||||||||||||||||
| 162 | # not a super class of the specified object. | ||||||||||||||||||||||||||||
| 163 | # This logic is in both get() and is_loaded(). | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 266 | my $quit_early = 0; | |||||||||||||||||||||||||||
| 166 | 266 | ▶ | if ( @_ == 2 && !ref($_[1]) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ == 2 and not ref $_[1]
MC/DC0%0/2
@_ == 2 and not ref $_[1]
@_ == 2
not ref $_[1]
Truth table33%1/3
A and not(B)
A= @_ == 2B= not ref $_[1]
| |||||||||||||||||||||||||||||
| 167 | 0 | ▶ | unless (defined($_[1])) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 168 | 0 | Carp::confess(); | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | 0 | my $obj = $UR::Context::all_objects_loaded->{$_[0]}->{$_[1]}; | |||||||||||||||||||||||||||
| 171 | 0 | ▶ | return $obj if $obj; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | # we could safely return nothing right now, except | ||||||||||||||||||||||||||||
| 173 | # that a subclass of this type may have the object | ||||||||||||||||||||||||||||
| 174 | 0 | ▶ | return unless $_[0]->__meta__->subclasses_loaded; # nope, there were no subclasses | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 266 | my $class = shift; | |||||||||||||||||||||||||||
| 178 | 266 | my $rule = UR::BoolExpr->resolve_normalized($class,@_); | |||||||||||||||||||||||||||
| 179 | 266 | return $UR::Context::current->get_objects_for_class_and_rule($class,$rule,0); | |||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 0 | ▶ | sub subclasses_loaded { | ||||||||||||||||||||||||||
|
Subroutine
subclasses_loaded: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 183 | 0 | return shift->__meta__->subclasses_loaded(); | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | # THESE SHOULD PROBABLY GO ON THE CLASS META | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 0 | ▶ | sub all_objects_are_loaded { | ||||||||||||||||||||||||||
|
Subroutine
all_objects_are_loaded: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 189 | # Keep track of which classes claim that they are completely loaded, and that no more loading should be done. | ||||||||||||||||||||||||||||
| 190 | # Classes which have the above function return true should set this after actually loading everything. | ||||||||||||||||||||||||||||
| 191 | # This class will do just that if it has to load everything itself. | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 194 | #$meta = $class->__meta__; | ||||||||||||||||||||||||||||
| 195 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 196 | # Setting the attribute | ||||||||||||||||||||||||||||
| 197 | 0 | $UR::Context::all_objects_are_loaded->{$class} = shift; | |||||||||||||||||||||||||||
| 198 | } elsif (! exists $UR::Context::all_objects_are_loaded->{$class}) { | ||||||||||||||||||||||||||||
| 199 | # unknown... ask the parent classes and remember the answer | ||||||||||||||||||||||||||||
| 200 | 0 | foreach my $parent_class ( $class->inheritance ) { | |||||||||||||||||||||||||||
| 201 | 0 | ▶ | if (exists $UR::Context::all_objects_are_loaded->{$parent_class}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 202 | 0 | $UR::Context::all_objects_are_loaded->{$class} = $UR::Context::all_objects_are_loaded->{$parent_class}; | |||||||||||||||||||||||||||
| 203 | 0 | last; | |||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | 0 | return $UR::Context::all_objects_are_loaded->{$class}; | |||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | # Observer pattern (old) | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 0 | ▶ | sub create_subscription { | ||||||||||||||||||||||||||
|
Subroutine
create_subscription: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 214 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 215 | 0 | my %params = @_; | |||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | # parse parameters | ||||||||||||||||||||||||||||
| 218 | 0 | my ($class,$id,$method,$callback,$note,$priority); | |||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | 0 | my %translate = ( | |||||||||||||||||||||||||||
| 221 | method => 'aspect', | ||||||||||||||||||||||||||||
| 222 | id => 'subject_id', | ||||||||||||||||||||||||||||
| 223 | ); | ||||||||||||||||||||||||||||
| 224 | 0 | my @param_names = qw(method callback note priority id); | |||||||||||||||||||||||||||
| 225 | 0 | my %observer_params; | |||||||||||||||||||||||||||
| 226 | 0 | for my $name (@param_names) { | |||||||||||||||||||||||||||
| 227 | 0 | ▶ | if (exists $params{$name}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 228 | 0 | ▶ | my $obs_name = $translate{$name} || $name; | ||||||||||||||||||||||||||
|
Condition0%0/3
$translate{$name} || $name
MC/DC0%0/2
$translate{$name} || $name
$translate{$name}
$name
Truth table0%0/3
A || B
A= $translate{$name}B= $name
| |||||||||||||||||||||||||||||
| 229 | 0 | $observer_params{$obs_name} = delete $params{$name}; | |||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 0 | $observer_params{'subject_class_name'} = $self->class; | |||||||||||||||||||||||||||
| 234 | 0 | ▶ | if (!defined $observer_params{'subject_id'} and ref($self)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $observer_params{"subject_id"} and ref $self
MC/DC0%0/2
not defined $observer_params{"subject_id"} and ref $self
not defined $observer_params{"subject_id"}
ref $self
Truth table0%0/3
not(A) and B
A= not defined $observer_params{"subject_id"}B= ref $self
| |||||||||||||||||||||||||||||
| 235 | 0 | $observer_params{'subject_id'} = $self->id; | |||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 0 | ▶ | if (my @unknown = keys %params) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 239 | 0 | Carp::croak "Unknown options @unknown passed to create_subscription!"; | |||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | # validate | ||||||||||||||||||||||||||||
| 243 | 0 | ▶ | if (my @bad_params = %params) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 244 | 0 | Carp::croak "Bad params passed to add_listener: @bad_params"; | |||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | 0 | my $observer = UR::Observer->create(%observer_params); | |||||||||||||||||||||||||||
| 248 | 0 | ▶ | return unless $observer; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 249 | 0 | return [@observer_params{'subject_class_name','subject_id','aspect','callback','note'}]; | |||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | sub validate_subscription | ||||||||||||||||||||||||||||
| 254 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
validate_subscription: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 255 | # Everything is invalid unless you make it valid by implementing | ||||||||||||||||||||||||||||
| 256 | # validate_subscription on your class. (Or use the new API.) | ||||||||||||||||||||||||||||
| 257 | 0 | return; | |||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | sub inform_subscription_cancellation | ||||||||||||||||||||||||||||
| 262 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
inform_subscription_cancellation: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 263 | # This can be overridden in derived classes if the class wants to know | ||||||||||||||||||||||||||||
| 264 | # when subscriptions are cancelled. | ||||||||||||||||||||||||||||
| 265 | 0 | return 1; | |||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | sub cancel_change_subscription ($@) | ||||||||||||||||||||||||||||
| 270 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
cancel_change_subscription: not called CC=13 SCAR=52.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 271 | 0 | my ($class,$id,$property,$callback,$note); | |||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | 0 | ▶ | if (@_ >= 4) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 274 | { | ||||||||||||||||||||||||||||
| 275 | 0 | ($class,$id,$property,$callback,$note) = @_; | |||||||||||||||||||||||||||
| 276 | 0 | ▶ | die "Bad parameters." if ref($class); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||
| 278 | ▶ | elsif ( (@_==3) or (@_==2) ) | |||||||||||||||||||||||||||
|
Condition0%0/3
@_ == 3 or @_ == 2
MC/DC0%0/2
@_ == 3 or @_ == 2
@_ == 3
@_ == 2
Truth table0%0/3
A or B
A= @_ == 3B= @_ == 2
| |||||||||||||||||||||||||||||
| 279 | { | ||||||||||||||||||||||||||||
| 280 | 0 | ($class, $property, $callback) = @_; | |||||||||||||||||||||||||||
| 281 | 0 | ▶ | if (ref($_[0])) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 282 | { | ||||||||||||||||||||||||||||
| 283 | 0 | $class = ref($_[0]); | |||||||||||||||||||||||||||
| 284 | 0 | $id = $_[0]->id; | |||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||
| 287 | else | ||||||||||||||||||||||||||||
| 288 | { | ||||||||||||||||||||||||||||
| 289 | 0 | die "Bad parameters."; | |||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | 0 | my %params; | |||||||||||||||||||||||||||
| 293 | 0 | ▶ | if (defined $class) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 294 | 0 | $params{'subject_class_name'} = $class; | |||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||
| 296 | 0 | ▶ | if (defined $id) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 297 | 0 | $params{'subject_id'} = $id; | |||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||
| 299 | 0 | ▶ | if (defined $property) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 300 | 0 | $params{'aspect'} = $property; | |||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||
| 302 | 0 | ▶ | if (defined $callback) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 303 | 0 | $params{'callback'} = $callback; | |||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||
| 305 | 0 | ▶ | if (defined $note) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 306 | 0 | $params{'note'} = $note; | |||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | 0 | my @observers = UR::Observer->get(%params); | |||||||||||||||||||||||||||
| 310 | 0 | ▶ | return unless @observers; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 311 | 0 | ▶ | if (@observers > 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 312 | Carp::croak('Matched more than one observer within cancel_change_subscription(). Params were: ' | ||||||||||||||||||||||||||||
| 313 | 0 | . join(', ', map { "$_ => " . $params{$_} } keys %params)); | |||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||
| 315 | 0 | $observers[0]->delete(); | |||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | # This should go away when we shift to fully to a transaction log for deletions. | ||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | 0 | ▶ | sub ghost_class { | ||||||||||||||||||||||||||
|
Subroutine
ghost_class: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 321 | 0 | my $class = $_[0]->class; | |||||||||||||||||||||||||||
| 322 | 0 | $class = $class . '::Ghost'; | |||||||||||||||||||||||||||
| 323 | 0 | return $class; | |||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | package UR::ModuleBase; | ||||||||||||||||||||||||||||
| 328 | # Method for setting a callback using the old, non-command messaging API | ||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | =pod | ||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | =over 4 | ||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | =item message_callback | ||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | $sub_ref = UR::ModuleBase->message_callback($type); | ||||||||||||||||||||||||||||
| 337 | UR::ModuleBase->message_callback($type, $sub_ref); | ||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | This method returns and optionally sets the subroutine that handles | ||||||||||||||||||||||||||||
| 340 | messages of a specific type. | ||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | =back | ||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||
| 344 | =cut | ||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | ## set or return a callback that has been created for a message type | ||||||||||||||||||||||||||||
| 347 | sub message_callback | ||||||||||||||||||||||||||||
| 348 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
message_callback: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 349 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 350 | 0 | my ($type, $callback) = @_; | |||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | 0 | my $methodname = $type . '_messages_callback'; | |||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | 0 | ▶ | if (!$callback) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 355 | # to clear the old, deprecated non-command messaging API callback | ||||||||||||||||||||||||||||
| 356 | 0 | return UR::Object->$methodname($callback); | |||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | 0 | ▶ | my $wrapper_callback = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 360 | 0 | my($obj,$msg) = @_; | |||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | 0 | my $obj_class = $obj->class; | |||||||||||||||||||||||||||
| 363 | 0 | ▶ | my $obj_id = (ref($obj) ? ($obj->can("id") ? $obj->id : $obj) : $obj); | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | 0 | my $message_package = $type . '_package'; | |||||||||||||||||||||||||||
| 366 | 0 | ▶ | my $message_object = UR::ModuleBase::Message->create | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 367 | ( | ||||||||||||||||||||||||||||
| 368 | text => $msg, | ||||||||||||||||||||||||||||
| 369 | level => 1, | ||||||||||||||||||||||||||||
| 370 | package_name => $obj->$message_package(), | ||||||||||||||||||||||||||||
| 371 | call_stack => ($type eq "error" ? _current_call_stack() : []), | ||||||||||||||||||||||||||||
| 372 | time_stamp => time, | ||||||||||||||||||||||||||||
| 373 | type => $type, | ||||||||||||||||||||||||||||
| 374 | owner_class => $obj_class, | ||||||||||||||||||||||||||||
| 375 | owner_id => $obj_id, | ||||||||||||||||||||||||||||
| 376 | ); | ||||||||||||||||||||||||||||
| 377 | 0 | $callback->($message_object, $obj, $type); | |||||||||||||||||||||||||||
| 378 | 0 | $_[1] = $message_object->text; | |||||||||||||||||||||||||||
| 379 | 0 | }; | |||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||
| 381 | # To support the old, deprecated, non-command messaging API | ||||||||||||||||||||||||||||
| 382 | 0 | UR::Object->$methodname($wrapper_callback); | |||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | sub message_object | ||||||||||||||||||||||||||||
| 386 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
message_object: not called CC=5 SCAR=30.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 387 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 388 | # see how we were called | ||||||||||||||||||||||||||||
| 389 | 0 | ▶ | if (@_ < 2) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 390 | { | ||||||||||||||||||||||||||||
| 391 | 266 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 392 | # return the message object | ||||||||||||||||||||||||||||
| 393 | 0 | my ($type) = @_; | |||||||||||||||||||||||||||
| 394 | 0 | my $method = $type . '_message'; | |||||||||||||||||||||||||||
| 395 | 0 | my $msg_text = $self->method(); | |||||||||||||||||||||||||||
| 396 | 0 | my $obj_class = $self->class; | |||||||||||||||||||||||||||
| 397 | 0 | ▶ | my $obj_id = (ref($self) ? ($self->can("id") ? $self->id : $self) : $self); | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 398 | 0 | my $msgdata = $self->_get_msgdata(); | |||||||||||||||||||||||||||
| 399 | return UR::ModuleBase::Message->create | ||||||||||||||||||||||||||||
| 400 | ( | ||||||||||||||||||||||||||||
| 401 | text => $msg_text, | ||||||||||||||||||||||||||||
| 402 | level => 1, | ||||||||||||||||||||||||||||
| 403 | 0 | ▶ | package_name => $msgdata->{$type . '_package'}, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 404 | call_stack => ($type eq "error" ? _current_call_stack() : []), | ||||||||||||||||||||||||||||
| 405 | time_stamp => time, | ||||||||||||||||||||||||||||
| 406 | type => $type, | ||||||||||||||||||||||||||||
| 407 | owner_class => $obj_class, | ||||||||||||||||||||||||||||
| 408 | owner_id => $obj_id, | ||||||||||||||||||||||||||||
| 409 | ); | ||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | 266 | foreach my $type ( UR::ModuleBase->message_types ) { | |||||||||||||||||||||||||||
| 414 | 1596 | my $retriever_name = $type . '_text'; | |||||||||||||||||||||||||||
| 415 | 1596 | my $compat_name = $type . '_message'; | |||||||||||||||||||||||||||
| 416 | 0 | ▶ | my $sub = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 417 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 418 | 0 | return $self->$compat_name(); | |||||||||||||||||||||||||||
| 419 | 1596 | }; | |||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | 266 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 422 | 1596 | *$retriever_name = $sub; | |||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||
| 426 | # class that stores and manages messages for the deprecated API | ||||||||||||||||||||||||||||
| 427 | package UR::ModuleBase::Message; | ||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | 266 | ▶ | use Scalar::Util qw(weaken); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||
| 431 | ##- use UR::Util; | ||||||||||||||||||||||||||||
| 432 | 266 | UR::Util->generate_readonly_methods | |||||||||||||||||||||||||||
| 433 | ( | ||||||||||||||||||||||||||||
| 434 | text => undef, | ||||||||||||||||||||||||||||
| 435 | level => undef, | ||||||||||||||||||||||||||||
| 436 | package_name => undef, | ||||||||||||||||||||||||||||
| 437 | call_stack => [], | ||||||||||||||||||||||||||||
| 438 | time_stamp => undef, | ||||||||||||||||||||||||||||
| 439 | owner_class => undef, | ||||||||||||||||||||||||||||
| 440 | owner_id => undef, | ||||||||||||||||||||||||||||
| 441 | type => undef, | ||||||||||||||||||||||||||||
| 442 | ); | ||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | sub create | ||||||||||||||||||||||||||||
| 445 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
create: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 446 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 447 | 0 | my $obj = {@_}; | |||||||||||||||||||||||||||
| 448 | 0 | bless ($obj,$class); | |||||||||||||||||||||||||||
| 449 | 0 | ▶ | weaken $obj->{'owner_id'} if (ref($obj->{'owner_id'})); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||
| 451 | 0 | return $obj; | |||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||
| 454 | sub owner | ||||||||||||||||||||||||||||
| 455 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
owner: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 456 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 457 | 0 | my ($owner_class,$owner_id) = ($self->owner_class, $self->owner_id); | |||||||||||||||||||||||||||
| 458 | 0 | ▶ | if (not defined($owner_id)) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 459 | { | ||||||||||||||||||||||||||||
| 460 | 0 | return $owner_class; | |||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||
| 462 | elsif (ref($owner_id)) | ||||||||||||||||||||||||||||
| 463 | { | ||||||||||||||||||||||||||||
| 464 | 0 | return $owner_id; | |||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||
| 466 | else | ||||||||||||||||||||||||||||
| 467 | { | ||||||||||||||||||||||||||||
| 468 | 0 | return $owner_class->get($owner_id); | |||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||
| 472 | sub string | ||||||||||||||||||||||||||||
| 473 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
string: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 474 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 475 | 0 | "$self->{time_stamp} $self->{type}: $self->{text}\n"; | |||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||
| 478 | sub _stack_item_params | ||||||||||||||||||||||||||||
| 479 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_stack_item_params: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 480 | 0 | my ($self, $stack_item) = @_; | |||||||||||||||||||||||||||
| 481 | 0 | my ($function, $parameters, @parameters); | |||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||
| 483 | 0 | ▶ | return unless ($stack_item =~ s/\) called at [^\)]+ line [^\)]+\s*$/\)/); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||
| 485 | 0 | ▶ | if ($stack_item =~ /^\s*([^\(]*)(.*)$/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 486 | { | ||||||||||||||||||||||||||||
| 487 | 0 | $function = $1; | |||||||||||||||||||||||||||
| 488 | 0 | $parameters = $2; | |||||||||||||||||||||||||||
| 489 | 0 | @parameters = eval $parameters; | |||||||||||||||||||||||||||
| 490 | 0 | return ($function, @parameters); | |||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||
| 492 | else | ||||||||||||||||||||||||||||
| 493 | { | ||||||||||||||||||||||||||||
| 494 | 0 | return; | |||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||
| 498 | package UR::Object; | ||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||
| 501 | 266 | 1; | |||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||