WeakRef::Auto - Automatically makes references weaken


WeakRef-Auto documentation Contained in the WeakRef-Auto distribution.

Index


Code Index:

NAME

Top

WeakRef::Auto - Automatically makes references weaken

VERSION

Top

This document describes WeakRef::Auto version 0.02.

SYNOPSIS

Top

	use WeakRef::Auto;

	autoweaken my $ref; # $ref is always weaken

	$ref = \$var; # $ref is weak

	sub MyNode::new{
		# ...
		autoweaken $self->{parent}; # parent is always weaken
		return $self;
	}

DESCRIPTION

Top

This module provides autoweaken(), which keeps references weaken.

FUNCTIONS

Top

autoweaken($var)

Turns $var into auto-weaken variables, and keeps the values weak references. If $var already has a reference, it is weaken on the spot.

$var can be an element of hashes or arrays.

NOTES

Top

BUGS AND LIMITATIONS

Top

autoweaken() does not work with tied variables, because autoweaken-ness is attached to the variable, not to the value referred by the variable, and tied variables interact with their objects by values, not variables, as the following shows:

  my $impl = tie my %hash, 'Tie::StdHash';
  autoweaken $hash{foo};
  # $hash{foo} seems autoweaken. Really?
  # Actually, $hash{foo} is linked to $impl->{foo} through FETCH()/STORE() methods,
  # but there is no way to detect the relationship.

Patches are welcome.

DEPENDENCIES

Top

Perl 5.8.1 or later.

SEE ALSO

Top

Scalar::Util for a description of weak references.

AUTHOR

Top

Goro Fuji <gfuji(at)cpan.org>.

LICENSE AND COPYRIGHT

Top


WeakRef-Auto documentation Contained in the WeakRef-Auto distribution.

package WeakRef::Auto;

use 5.008_001;
use strict;

our $VERSION = '0.02';

use Exporter qw(import);
our @EXPORT = qw(autoweaken);

sub autoweaken(\$);

use XSLoader;
XSLoader::load(__PACKAGE__, $VERSION);

1;
__END__