Passing user data to request callback

Gisle.Aas@nr.no
Tue, 28 Feb 95 12:41:53 +0100


m.koster@nexor.co.uk writes:
> What interface is require for the callback (ie what do we pass it?) I
> currently pass &$callback($content, $nread);, but you might want to
> pass more... The library might want to supply headers and result
> codes, and the user might need some specific data. Maybe you could
> pass a magic cookie along so people can always pass their own objects
> to store state data the callback might need:
> 
>   &request(... $code, $magic);
> 
>   sub request {
>      ...
>      &$code($content, $nread, $magic, $outheaderref, ...);   

I think the $magic stuff is not needed.  Perl 5.001 implements
closures which should be able to handle this better.  You should be
able to say:

     my $magic;
     $rc = request(..., sub { ...; something($magic)... }, ...);

--Gisle