[ic] Subroutines and ActionMaps

Mike Heins interchange-users@icdevgroup.org
Mon Jan 27 12:08:00 2003


Quoting Mark Gibson (gibsonm@cromwell-tools.co.uk):
> On Monday 27 Jan 2003 2:53 pm, Mike Heins wrote:
> > 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
> 
> I'm having another problem regarding 'Sub', they don't seem to work in
> [perl] blocks.
> 
> Lets assume we have defined the do_stuff() sub as above.
> The following doesn't work (within an HTML page):
> 
> [perl] return do_stuff(); [/perl]
> 
> I keep getting (in global error log):
> Safe: Undefined subroutine &main::do_stuff called at (tag 'perl') line 1.
> >
> > return do_stuff();
> >
> 
> BUT, the following works fine:
> 
> [perl] return $Config->{Sub}{do_stuff}->(); [/perl]
> 
> Have I missed something, or is this a bug?

No, it is not -- you did not use the subs=1 parameter as documented.

> 
> I think it would be a useful feature if 'Sub' routines could be called from
> anywhere in the catalogue, (ie. ActionMaps, UserTags, other Subs, [perl], 
> [calc], [mvasp], etc.)
> as there doesn't seem to be anywhere else to place reuseable functions
> (or again, have I overlooked something?)

There is a place -- UserTag. It has the advantage of being callable
from ITL, and is easily accessed via $Tag->routine().

In addition, unless you are somehow limited in your permissions, it
is usually more useful to define global UserTag and ActionMap things.

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

Nature, to be commanded, must be obeyed. -- Francis Bacon