You are viewing a plain text version of this content. The canonical link for it is here.
Posted to asp@perl.apache.org by raptor <ra...@unacs.bg> on 2001/07/31 18:52:13 UTC

[off] giving call-back-func parameters...

hi,

sorry if this is a litle bit off-topic, but doesn't know where to post it...
Of all 10 mailing lists and 11 newsgroups this seems to be most suitable
:")... so here is it :

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_parameter
=> '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 !!
=====
iVAN
raptor@unacs.bg
=====







---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


Re: [off] giving call-back-func parameters...

Posted by will trillich <wi...@serensoft.com>.
On Tue, Jul 31, 2001 at 07:52:13PM +0300, raptor wrote:
> 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....

my $callbackFunc = sub { &Helper::func(something=>$here, also=>$this, @_) }

maybe?

-- 
Khan said that revenge is a dish best served cold. I think 
sometimes it's best served hot, chunky, and foaming. 
	- P.J.Lee ('79-'80)
 
will@serensoft.com
http://sourceforge.net/projects/newbiedoc -- we need your brain!
http://www.dontUthink.com/ -- your brain needs us!

Re: [off] giving call-back-func parameters...

Posted by raptor <ra...@unacs.bg>.
thanx alot..


---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


Re: [off] giving call-back-func parameters...

Posted by Joshua Chamas <jo...@chamas.com>.
raptor wrote:
> 
> 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} );
>    ..............
> };
> ....
> 

Let's say your vals gets executed in a subroutine call dispatch(),
then you can pass your args to dispatch() at runtime, and have
it call into your callback with these args, like

$bigOne->dispatch('vars', @args);

sub dispatch {
  my($self, $sub_name, @args) = @_;
  my $code = $self->{$sub_name};
  my $kv = &$code(@args);  
}

Binding your args at runtime will be the most flexible

This is actually how $Response->Include($include, @args) works,
by compiling $include files into a asp perl sub, and then
executing it with @args passed in.

--Josh

_________________________________________________________________
Joshua Chamas                           Chamas Enterprises Inc.
NodeWorks Founder                       Huntington Beach, CA  USA 
http://www.nodeworks.com                1-714-625-4051

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org