NAME

Hash::NoRef - A HASH that store values without increse the reference count.

DESCRIPTION

This HASH will store it's values without increse the reference count. This can be used to store objects but without interfere in the DESTROY mechanism, since the reference in this HASH won't count.

USAGE

use Hash::NoRef ;

my $hash = new Hash::NoRef() ;

{
  my $obj = new FOO() ;
  $hash->{obj} = $obj ;
  ## When we exit this block $obj will be destroied,
  ## even with it stored in $hash->{obj}
}

FUNTIONS

SvREFCNT ( REF )

Return the reference count of a reference. If a reference is not paste it will return -1. Dead references will return 0.

Note that internally we make -1 to the reference count:

RETVAL = SvREFCNT(sv) - 1 ;

Since when we make \$var we are actually creating a reference. So, for objects or reference to anonymous SCALAR, ARRAY, HASH, it will return 0. To avoid that alwasy paste creating a reference:

my $hash = {} ;
print Hash::NoRef::SvREFCNT( $hash ) ; ## returns 0
print Hash::NoRef::SvREFCNT( \%$hash ) ; ## returns 1

SvREFCNT_inc ( REF )

Increase the reference count.

SvREFCNT_dec ( REF )

Decrease the reference count.

EXAMPLES

my $var = 123 ;
$refcnt = Hash::NoRef::SvREFCNT( \$var ) ; ## returns 1

Hash::NoRef::SvREFCNT_inc(\$var) ; ## adda fake reference, so, it will never die.
Hash::NoRef::SvREFCNT_dec(\$var) ; ## get back to the normal reference count.

SEE ALSO

Spy, Devel::Peek, Safe::World.

AUTHOR

Graciliano M. P. <gm@virtuasites.com.br>

I will appreciate any type of feedback (include your opinions and/or suggestions). ;-P

COPYRIGHT

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.