Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

appending params to call-back

by raptor (Sexton)
on Jul 31, 2001 at 23:00 UTC ( [id://101277]=perlquestion: print w/replies, xml ) Need Help??

raptor has asked for the wisdom of the Perl Monks concerning the following question:

hi,
I have the following situation :

A main module BigOne.pm a Helper.pm(here i have required function implemented), so in the script I have something like this :
script.pl
===========
use Helper;
my $callbackFunc = \&Helper::func; my $obj = new BigOne ( vals => $callbackFunc);

BigOne.pm
==========
my $vals = shift; .... if (ref $vals eq 'CODE') { ........... my $kv = &$vals( id => $selected, dbh => $$self{dbh} ); .............. }; ....

See $kv gets the return value from Helper::func(), everything is OK until I need to pass one more parameter to this function which I don't know in BigOne.pm but know at script.pl.... i.e. I want to say something like this :
my $callbackFunc = \&Helper::func( additional_parameter => 'xxx' );
and then the real call (in BigOne) has to become :
my $kv = &$vals( id => $selected, dbh => $$self{dbh}, additional_param +eter => 'xxx' );
instead of just :
my $kv = &$vals( id => $selected, dbh => $$self{dbh});

Any help very appricated....

PS. One possible solution is to pass one or more parameters at the creation of BigOne object but this is not acceptable in my case.. 'cause it is a little bit more complicated .. One last-resort solution is to create a function in script.pl which will get the parameters from &$vals()-call and then redispach/recall Helper::func() on its behalf!...
i.e. behave like proxy ( BigOne-&vals --script.pl-->Helper::func() ) ..
is there better way !? 'cause if I use this way I have to also take care for return values which can be a ref-ARRAY but also can be flattened array with alot of elements :"(
Thanx again and sorry for loosing your time !!

Replies are listed 'Best First'.
Re: appending params to call-back
by John M. Dlugosz (Monsignor) on Jul 31, 2001 at 23:16 UTC
    my $callbackFunc = sub {Helper::func( @_, additional_parameter => 'xxx +' ); };
    Should be what you're looking for.

    —John

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://101277]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-03-28 16:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found