Re: Question about Watcher Attributes

[email protected] (Joshua N Pritikin)
Newsgroups perl.loop
Message-ID <[email protected]>
On Tue, Apr 18, 2000 at 06:18:04PM -0400, [email protected] wrote:
> >>>>> "JNP" == Joshua N Pritikin <[email protected]> writes:
>   JNP>   $watcher->{data} = ...;
> 
> <SMACK!>

;-)  X-)  :-(  :-}

> being the one who asked for and got this attribute added, i vehemently
> oppose that bit of code. you are breaking all rules of OO
> coding. $watcher (or the $event passed into a callback) is an object
> with no implementation implied. the code should be a method call:
> 
> 	$watcher->data( 'foo' ) ;

Hm.

> i assume (i haven't checked the docs in this) that it is a single
> accessor method which sets the value if given an argument and gets it
> back always.

I didn't document it yet.

> the purpose of the data attribute is to associate some private data with
> a watcher/event and the callback was not an object/method. so when the
> event is triggered, you can look into the data value and see which
> thing (e.g. socket) caused the trigger and get at buffers and other data
> related to that socket. this eliminates any tricky lookups based on the
> socket.

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__ }
  }

Maybe data can be imported or auto-created somehow...

-- 
"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.