Re: Question about Watcher Attributes

[email protected] (Joshua N Pritikin)
Newsgroups perl.loop
Message-ID <[email protected]>
On Wed, Apr 19, 2000 at 12:08:12PM -0400, [email protected] wrote:
> >>>>> "JNP" == Joshua N Pritikin <[email protected]> writes:
> 
>   >> sub privateData
>   >> {
>   >> my $obj = shift;
>   >> my $key = shift || caller;
>   >> $obj->{$key} ||= {};
>   >> }
> 
> i am not sure of why the need for private data per caller. i used the
> data attribute in a global way when i wrote event loops.

What if I inherit from your customized watcher and wish to store my own
private data?  That was my hesitation all along, but now it looks
solved.

>   JNP> sub data {  # assumes $self is a HASH ref
>   JNP>     my $self = shift;
>   JNP>     my $pkg = caller;
>   JNP>     if (@_) {
>   JNP> 	$self->{$pkg} = shift
>   JNP>     } else {
> 
> drop the else. accessors should always return the value whether freshly
> set or not.

Yes, that how it works either way.  Hash assignment returns the new
value; the else branch would be redundent.

-- 
"May the best description of competition prevail."
          via, but not speaking for Deutsche Bank
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.