jepri has asked for the wisdom of the Perl Monks concerning the following question:
use webdav; my %callback = ( get_properties => \&get_properties_callb +ack, get_content => \&get_content, get_options => \&get_options, put_content => \&put_content, move_member => \&move_member, copy_member => \©_member, make_collection => \&make_collection, delete_member => \&delete_member, ); webdavlisten(%callback); package webdav; #Exports, etc etc sub webdavlisten { my %callback = @_; ... &{$callback{get_content}}(data...);
The callbacks work, but when any of the callback code calls another fuction, it calls it in the webdav package. Naturally the user is going to want to add a few support routines for his callbacks. The only thing I can think of to do is to use the caller function to see where webdavlisten is being called from, but even that is inelegant because there is no compulsion to call webdavlisten from the same package that the callbacks are defined in.
I'm happy to jettison the coderef callback and go OO if neccessary, but it seemed to me that this provided the most convenient way to pass the functions.
____________________
Jeremy
I didn't believe in evil until I dated it.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Passing coderefs across packages and calling them in the wrong package
by dmmiller2k (Chaplain) on Feb 23, 2002 at 04:06 UTC | |
by jepri (Parson) on Feb 23, 2002 at 08:27 UTC |