Re: Question about Watcher Attributes
[email protected] (Joshua N Pritikin)
| Newsgroups | perl.loop |
|---|---|
| Message-ID | <[email protected]> |
On Wed, Apr 19, 2000 at 08:36:21AM +0100, [email protected] wrote: > 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: > > Graham Barr came up with this for Tk: > > sub privateData > { > my $obj = shift; > my $key = shift || caller; > $obj->{$key} ||= {}; > } Oh, that's clever. How about this? =item data => $anything Use the C<data()> method to associate arbitrary data with a watcher. Each caller's package accesses its own private data attribute. =cut sub data { # assumes $self is a HASH ref my $self = shift; my $pkg = caller; if (@_) { $self->{$pkg} = shift } else { $self->{$pkg}; } } -- "May the best description of competition prevail." via, but not speaking for Deutsche Bank