----- Original Message ----- 
From: "Graciliano M. P." <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: 16 April 2004 08:58
Subject: New module Hash::NoRef


> I need some tests of this new module.
> 
> Thanks in advance.
> 
> From POD:
> ---------------------------------------------------
> 
> =head1 NAME
> 
> Hash::NoRef - A HASH that store values without increse the reference count.
> 
> =head1 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
> references in this HASH won't count.

You need to define precisely what it is that the module does before writing tests. 
You need to consider (and document in the POD) what exceptions can happen 
and how your module will handle them.

This should be the basis for some of your tests.

Are you talking about references to the HASH itself, or reference to its members?
>From your POD this is not clear.
 
> =head1 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}
>   }
> 

Ah, looks like the hash members are the ones not adding to the reference count.

OK so, you are allowed to add scalars to the hash, without these scalars
having their refcounts incremented.

Why would you want to do this? After $obj has been DESTROYed, what is 
$hash->{obj} pointing to? eh? This will result in potential segfaults when you
attempt to access $hash->{obj}

> ---------------------------------------------------
> 
> This can be useful if you need to keep a table of objects, but don't want to
> mess with the "DESTROY mechanism".

What are you offering over and above what weaken does in Scalar::Util?
 
> Just wait CPAN to write it at:
> http://www.cpan.org/authors/id/G/GM/GMPASSOS/Hash-NoRef-0.01.tar.gz

Another thought: how about using a tie interface? This would be more natural 
for the programmer using your module.

My $0.02

Ivor.

Reply via email to