[ic] Subroutines and ActionMaps

Mike Heins interchange-users@icdevgroup.org
Mon Jan 27 09:54:00 2003


Quoting Mike Heins (mike@perusion.com):
> Quoting Mark Gibson (gibsonm@cromwell-tools.co.uk):
> > Hello again,
> > 	I've come up against another brick wall while attempting to make
> > use of the ActionMap feature.
> > 
> > Where would I define a subroutine that I wish to call from within an 
> > ActionMap?
> > 
> > I've tried the 'Sub' directive, eg:
> > 
> > Sub <<EOF
> > sub do_stuff {
> > 	...
> > 	return $myresult;
> > }
> > EOF
> > 
> > ActionMap myaction <<EOF
> > sub {
> > 	...
> > 	my $stuff = do_stuff();
> > 	...
> > }
> > EOF
> > 
> > When I go to the URL (http://.../myaction) I just get the message:
> > 
> > Sorry, there was an error in processing this form action. Please report the 
> > error or try again later. (Undefined subroutine &main::do_stuff called at 
> > (eval 1783) line 4. )
> 
> That sub is not available in that context. You can do this, though:
> 
> ActionMap myaction <<EOF
> sub do_stuff {
> 	...
> 	return $myresult;
> }
> 
> sub {
> 	...
> 	my $stuff = do_stuff();
> 	...
> }
> EOF

One more note on this --- you can also call the Sub via:

Sub <<EOF
sub do_stuff {
	...
	return $myresult;
}
EOF

ActionMap myaction <<EOF
sub {
	...
	my $stuff = $Config->{Sub}{do_stuff}->();
	...
}
EOF

-- 
Mike Heins
Perusion -- Expert Interchange Consulting    http://www.perusion.com/
phone +1.513.523.7621      <mike@perusion.com>

Light travels faster than sound. This is why some people appear bright
until you hear them speak. -- unknown