On Fri, 28 Sep 2001 08:45, Tim Colson wrote: > Not sure how best to word the question - let me give more details. > > I'm trying to move runmode subs, which I'm going to call 'actions', into > their own class/file/package. > [snip] > > The problem I'm having is how to specify a reference to the workhorse > subroutine inside the action - called doPerform(). > > ----- > package JobAgent; > use base 'PerlAppFramework'; > > use ActionShowList; > my $action = new ActionShowList( $self->query() ); > > $self->run_modes( > 'mode1' => \&showform, > 'mode2' => \{$action->doPerform()} # naive attempt which barfs > ); > Barf error mesg: > [Thu Sep 27 15:08:30 2001] JobAgent: Error executing run mode 'mode2'. > Eval of code '$self->SCALAR(0x250564)' resulted in error: [Thu Sep 27 > 15:08:30 2001] JobAgent: Can't locate object method "SCALAR" via package > "JobAgent" at (eval 12) line 1, <STDIN> chunk 1. > > > I've searched perlmonks.org and of course the perltoot and perlobj -> > but can't seem to find out how to create a reference to a method of an > object.
You can do something like this with a closure. Although you should make sure you realize the implications of using them. Something like the following should work (untested) my $action = new ActionShowList( $self->query() ); my $closure = sub { $action->doPerform(); }; $self->run_modes( 'mode1' => \&showform, 'mode2' => $closure ); Cees Hek --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]