UR::DeletedRef(3pm)
π UR::DeletedRef β bestie, it's the ghost of an object that got deleted π
okay so real talk: this is UR::DeletedRef, a lil module from the User Contributed Perl Documentation collection, and it represents an instance of a no-longer-existent object. yes. an object that is gone. deceased. deleted. unalived, if you will. πͺ¦β¨
β¨ SYNOPSIS β¨
my $obj = Some::Class->get(123);
$obj->delete;
print ref($obj),"\n"; # prints 'UR::DeletedRef'
$obj->some_method(); # generates an exception through Carp::confess
$obj->resurrect;
print ref($obj),"\n"; # prints 'Some::Class'
like, watch the glow-up happen in real time. you grab your object with get(123), you call delete on it, and boom β ref($obj) now says 'UR::DeletedRef'. try to call $obj->some_method() and it will throw hands β an exception, via Carp::confess. then $obj->resurrect and suddenly ref($obj) is back to 'Some::Class'. the comeback era. π
πΈ DESCRIPTION πΈ
so here's the tea, bestie. object instances become UR::DeletedRefs when some part of the application calls delete() or unload() on them β meaning they no longer exist in that Context. the extant object reference gets turned into a UR::DeletedRef, and the whole point of that is: if that same reference gets used in any capacity later in the program, it will generate an exception through its AUTOLOAD. it's a safety net, fr fr. it prevents you from using a dead object by mistake. π«Ά
π not to be confused with Ghost objects, no cap
UR::DeletedRef instances are different than Ghost objects. let me break it down:
- when a UR-based object is deleted through
delete(), a new Ghost object reference is created from the data in the old object - and the old object reference is re-blessed as a
UR::DeletedRef - any variables still referencing the original object now hold a reference to this
UR::DeletedRef - the Ghost object can be retrieved by issuing a
get()against the Ghost class
so likeβ¦ the Ghost is the data's afterlife, and the UR::DeletedRef is the cursed lil pointer that used to be your object. two completely different vibes. π¦
π also they come from transactions too
objects unloaded from the Context using unload(), or indirectly by rolling-back a transaction which triggers unload of objects loaded during the transaction, are also turned into UR::DeletedRefs. so it's not always you doing it on purpose. sometimes the transaction said "no <3" and took everything with it. π
π will you ever actually meet one?
ngl, you aren't likely to encounter UR::DeletedRefs in normal use. what usually happens is this: an object gets deleted with delete() (or unload()), the lexical variable pointing to the DeletedRef will soon go out of scope, and the DeletedRef will then be garbage-colelcted. yes that spelling is in the original. we keep it. it's iconic. πβ¨
π₯ SEE ALSO π₯
UR::Objectβ the whole reason any of this existsUR::Object::Ghostβ the data's haunted afterlifeUR::Contextβ the place where objects live and, unfortunately, die
lowkey the whole module is just a "do not touch, this object is DEAD" sticker with main character energy. treat it with respect and it'll never yell at you through Carp::confess. π
okay that's the whole page bestie, periodt π this was UR::DeletedRef(3pm) from the User Contributed Perl Documentation, running on perl v5.32.1, dated 2022-01-17. go forth and never use a deleted reference again. slay. π§ββοΈπ
π¦ where this page comes from
- debian bookworm: libur-perl 0.470+ds-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libur-perl 0.470+ds-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libur-perl 0.470+ds-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms