Joshua N Pritikin <[EMAIL PROTECTED]> writes:
>
>Granted.  Perhaps the thing to do is to document that data() should
>be reimplemented in every subclass to use a uniqueish key:
>
>  sub data {
>    my ($o, $data) = @_;
>    $o->{ __PACKAGE__ } = $data if @_ > 1;
>    $o->{ __PACKAGE__ }
>  }

Graham Barr came up with this for Tk:

sub privateData
{
 my $obj = shift;
 my $key = shift || caller;
 $obj->{$key} ||= {};
}

The assumption there is that it always returns a hash ref.
But the caller-as-key techique should work fine. Above is in 
Tk::Widget so can be inherited by (almost) everything.

-- 
Nick Ing-Simmons <[EMAIL PROTECTED]>
Via, but not speaking for: Texas Instruments Ltd.

Reply via email to