Re: Question about Watcher Attributes

[email protected] (Uri Guttman)
Newsgroups perl.loop
Message-ID <[email protected].>
>>>>> "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.


  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.

	$self->{$pkg} = shift if @_ ;
	$self->{$pkg};

uri

-- 
Uri Guttman  ---------  [email protected]  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com
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.