Re: Question about Watcher Attributes

[email protected] (Uri Guttman)
Newsgroups perl.loop
Message-ID <[email protected].>
>>>>> "JNP" == Joshua N Pritikin <[email protected]> writes:

  JNP>   $watcher->{data} = ...;

<SMACK!>

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' ) ;

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.

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.

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.