Devel::WeakRef

Devel::WeakRef offers weak references (not reference-counted).
Download

Devel::WeakRef Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Jesse Glick
  • Publisher web site:
  • http://search.cpan.org/~jglick/Devel-WeakRef-0.003/lib/Devel/WeakRef.pm

Devel::WeakRef Tags


Devel::WeakRef Description

Devel::WeakRef offers weak references (not reference-counted). Devel::WeakRef offers weak references (not reference-counted).SYNOPSIS my $foo={a => 1, b => 2}; # Some sort of reference scalar. my $foo_=new Devel::WeakRef $foo; my $bar=$foo_->deref; # Hard ref through dereference $foo_->deref->{c}=3; # Dereference $foo=$bar=77; # OK, hash collected $foo_->deref; # Yields undef now $foo_->empty; # True now.Currently this also works: $$foo_->{a};But this dies with a stern message: $$foo_=$new_thingy; # Nope! Weak ref must never change referents.This hash table has weak references as values: tie my %table, Devel::WeakRef::Table; $table{key1}=$some_object; $table{key2}=$some_other_object; $table{key1}=$yet_another_object; # OK to replace keys like thisA weak reference maintains a "pointer" to an object (specified by a reference to it, just like bless) that does not contribute to the object's reference count; thus, the object's storage will be freed (and its destructor invoked) when only weak references remain to it. (It is fine to have multiple weak references to a single object.) The deref method derefences the weak reference. Dereferencing a weak reference whose target has already been destroyed results in undef.empty tests if the reference is invalid; $ref->empty is equivalent to !defined $ref->deref. For now, you can just use Perl's normal scalar dereference to the same effect; but be sure to use this for reading only. This interface may change.The package Devel::WeakRef::Table may be used to tie hashes so as to make their values all weak references. This is useful for caches in particular, where it would be more annoying to have to explicitly dereference the value each time. Requirements: · Perl


Devel::WeakRef Related Software