Re: Question about Watcher Attributes

[email protected] (Nick Ing-Simmons)
Newsgroups perl.loop
Organization via, but not speaking for : Texas Instruments Ltd.
Message-ID <[email protected]>
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.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.