« blib/lib/UR/DataSource/Meta.pm
↑ Summary
blib/lib/UR/BoolExpr/Template/PropertyComparison/NotIn.pm »
| 1 | ##### | ||||||||||||||
| 2 | # | ||||||||||||||
| 3 | # Support "Ghost" objects. These represent deleted items which are not saved. | ||||||||||||||
| 4 | # They are omitted from regular class lists. | ||||||||||||||
| 5 | # | ||||||||||||||
| 6 | ##### | ||||||||||||||
| 7 | |||||||||||||||
| 8 | package UR::Object::Ghost; | ||||||||||||||
| 9 | |||||||||||||||
| 10 | 266 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 266 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 266 | require UR; | |||||||||||||
| 13 | 266 | our $VERSION = "0.47"; # UR $VERSION; | |||||||||||||
| 14 | |||||||||||||||
| 15 | 0 | ▶ | sub _init_subclass { | ||||||||||||
|
Subroutine
_init_subclass: not called CC=1 SCAR=2.0
| |||||||||||||||
| 16 | 0 | my $class_name = pop; | |||||||||||||
| 17 | 266 | ▶ | no strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 18 | 266 | ▶ | no warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 19 | 0 | my $live_class_name = $class_name; | |||||||||||||
| 20 | 0 | $live_class_name =~ s/::Ghost$//; | |||||||||||||
| 21 | 0 | ▶ | *{$class_name ."\:\:class"} = sub { "$class_name" }; | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 22 | 0 | ▶ | *{$class_name ."\:\:live_class"} = sub { "$live_class_name" }; | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 23 | } | ||||||||||||||
| 24 | |||||||||||||||
| 25 | 0 | ▶ | sub create { Carp::croak('Cannot create() ghosts.') }; | ||||||||||||
|
Subroutine
create: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 26 | |||||||||||||||
| 27 | 0 | ▶ | sub delete { Carp::croak('Cannot delete() ghosts.') }; | ||||||||||||
|
Subroutine
delete: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 28 | |||||||||||||||
| 29 | 0 | ▶ | sub __rollback__ { | ||||||||||||
|
Subroutine
__rollback__: not called CC=7 SCAR=40.3
| |||||||||||||||
| 30 | 0 | my $self = shift; | |||||||||||||
| 31 | |||||||||||||||
| 32 | # revive ghost object | ||||||||||||||
| 33 | |||||||||||||||
| 34 | 0 | my $ghost_copy = eval("no strict; no warnings; " . Data::Dumper::Dumper($self)); | |||||||||||||
| 35 | 0 | ▶ | if ($@) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 36 | 0 | Carp::confess("Error re-constituting ghost object: $@"); | |||||||||||||
| 37 | } | ||||||||||||||
| 38 | 0 | my($saved_data, $saved_key); | |||||||||||||
| 39 | 0 | ▶ | if (exists $ghost_copy->{'db_saved_uncommitted'} ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 40 | 0 | $saved_data = $ghost_copy->{'db_saved_uncommitted'}; | |||||||||||||
| 41 | } elsif (exists $ghost_copy->{'db_committed'} ) { | ||||||||||||||
| 42 | 0 | $saved_data = $ghost_copy->{'db_committed'}; | |||||||||||||
| 43 | } else { | ||||||||||||||
| 44 | 0 | return; # This shouldn't happen?! | |||||||||||||
| 45 | } | ||||||||||||||
| 46 | |||||||||||||||
| 47 | 0 | my $new_object = $self->live_class->UR::Object::create(%$saved_data); | |||||||||||||
| 48 | 0 | ▶ | $new_object->{db_committed} = $ghost_copy->{db_committed} if (exists $ghost_copy->{'db_committed'}); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 49 | 0 | ▶ | $new_object->{db_saved_uncommitted} = $ghost_copy->{db_saved_uncommitted} if (exists $ghost_copy->{'db_saved_uncommitted'}); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 50 | 0 | ▶ | unless ($new_object) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 51 | 0 | Carp::confess("Failed to re-constitute $self!"); | |||||||||||||
| 52 | } | ||||||||||||||
| 53 | |||||||||||||||
| 54 | 0 | return $new_object; | |||||||||||||
| 55 | } | ||||||||||||||
| 56 | |||||||||||||||
| 57 | 0 | ▶ | sub _load { | ||||||||||||
|
Subroutine
_load: not called CC=1 SCAR=6.9
| |||||||||||||||
| 58 | 0 | shift->is_loaded(@_); | |||||||||||||
| 59 | } | ||||||||||||||
| 60 | |||||||||||||||
| 61 | |||||||||||||||
| 62 | 0 | ▶ | sub unload { | ||||||||||||
|
Subroutine
unload: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 63 | 0 | return; | |||||||||||||
| 64 | } | ||||||||||||||
| 65 | |||||||||||||||
| 66 | 0 | ▶ | sub __errors__ { | ||||||||||||
|
Subroutine
__errors__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 67 | 0 | return; # Ghosts are always valid, don't check their properties | |||||||||||||
| 68 | } | ||||||||||||||
| 69 | |||||||||||||||
| 70 | 0 | ▶ | sub edit_class { undef } | ||||||||||||
|
Subroutine
edit_class: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 71 | |||||||||||||||
| 72 | 0 | ▶ | sub ghost_class { undef } | ||||||||||||
|
Subroutine
ghost_class: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 73 | |||||||||||||||
| 74 | 0 | ▶ | sub is_ghost { return 1; } | ||||||||||||
|
Subroutine
is_ghost: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 75 | |||||||||||||||
| 76 | sub live_class | ||||||||||||||
| 77 | 0 | ▶ | { | ||||||||||||
|
Subroutine
live_class: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 78 | 0 | my $class = $_[0]->class; | |||||||||||||
| 79 | 0 | $class =~ s/::Ghost//; | |||||||||||||
| 80 | 0 | return $class; | |||||||||||||
| 81 | } | ||||||||||||||
| 82 | |||||||||||||||
| 83 | 266 | my @ghost_changes; | |||||||||||||
| 84 | 0 | ▶ | sub changed { | ||||||||||||
|
Subroutine
changed: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 85 | 0 | ▶ | @ghost_changes = UR::Object::Tag->create ( type => 'changed', properties => ['id']) unless @ghost_changes; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 86 | 0 | return @ghost_changes; | |||||||||||||
| 87 | } | ||||||||||||||
| 88 | |||||||||||||||
| 89 | sub AUTOSUB | ||||||||||||||
| 90 | 0 | ▶ | { | ||||||||||||
|
Subroutine
AUTOSUB: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 91 | # Delegate to the similar function on the regular class. | ||||||||||||||
| 92 | 0 | my ($func, $self) = @_; | |||||||||||||
| 93 | 0 | my $live_class = $self->live_class; | |||||||||||||
| 94 | 0 | return $live_class->can($func); | |||||||||||||
| 95 | } | ||||||||||||||
| 96 | |||||||||||||||
| 97 | 266 | 1; | |||||||||||||
| 98 | |||||||||||||||
| 99 | |||||||||||||||
| 100 | =pod | ||||||||||||||
| 101 | |||||||||||||||
| 102 | =head1 NAME | ||||||||||||||
| 103 | |||||||||||||||
| 104 | UR::Object::Ghost - Abstract class for representing deleted objects not yet committed | ||||||||||||||
| 105 | |||||||||||||||
| 106 | =head1 SYNOPSIS | ||||||||||||||
| 107 | |||||||||||||||
| 108 | my $obj = Some::Class->get(1234); | ||||||||||||||
| 109 | $obj->some_method(); | ||||||||||||||
| 110 | |||||||||||||||
| 111 | $obj->delete(); # $obj is now a UR::DeletedRef | ||||||||||||||
| 112 | |||||||||||||||
| 113 | $ghost = Some::Class::Ghost->get(1234); | ||||||||||||||
| 114 | $ghost->some_method; # Works | ||||||||||||||
| 115 | |||||||||||||||
| 116 | =head1 DESCRIPTION | ||||||||||||||
| 117 | |||||||||||||||
| 118 | Ghost objects are a bookkeeping entity for tracking objects which have been | ||||||||||||||
| 119 | loaded from an external data source, deleted within the application, and not | ||||||||||||||
| 120 | yet committed. This implies that they still exist in the external data | ||||||||||||||
| 121 | source. When the Context is committed, the existence of Ghost objects | ||||||||||||||
| 122 | triggers commands to the external data sources to also delete the object(s). | ||||||||||||||
| 123 | When objects are brought into the Context by querying a data source, they | ||||||||||||||
| 124 | are compared against any ghosts that may already exist, and matching objects | ||||||||||||||
| 125 | are not re-loaded or returned to the user from a call to get(). If the | ||||||||||||||
| 126 | user wants to get Ghost objects, they must call get() explicitly on the | ||||||||||||||
| 127 | Ghost class. | ||||||||||||||
| 128 | |||||||||||||||
| 129 | Each class in the system also has an associated Ghost class, the name of which | ||||||||||||||
| 130 | is formed by tacking '::Ghost' to the name of the regular class. Ghost | ||||||||||||||
| 131 | classes do not have ghosts themselves. | ||||||||||||||
| 132 | |||||||||||||||
| 133 | Instances of Ghosts are not instantiated with create() directly, they are | ||||||||||||||
| 134 | created as a concequence of deleting a regular object instance. A Ghost | ||||||||||||||
| 135 | can be turned back into a "live" object by re-creating it, or rolling back | ||||||||||||||
| 136 | the transaction it was deleted in. | ||||||||||||||
| 137 | |||||||||||||||
| 138 | =head1 DEPRECATED | ||||||||||||||
| 139 | |||||||||||||||
| 140 | Applications will not, and should not, normally interact with Ghosts. The | ||||||||||||||
| 141 | whole Ghost system is scheduled for elimination as we refactor the Context | ||||||||||||||
| 142 | and software transaction framework. | ||||||||||||||
| 143 | |||||||||||||||
| 144 | =head1 SEE ALSO | ||||||||||||||
| 145 | |||||||||||||||
| 146 | UR::Object, UR::Object::Type | ||||||||||||||
| 147 | |||||||||||||||
| 148 | =cut | ||||||||||||||
| 149 | |||||||||||||||