[ic] Calling subs from usertags
Kevin Walsh
kevin at cursor.biz
Mon Jun 13 10:46:53 EDT 2005
Daniel Browning [db at kavod.com] wrote:
> What is the best method to call subs from usertags? Here is what I've
> been using:
>
> For globalsubs from global usertags:
>
> $Global::GlobalSub->{ name_of_sub }->( 'arg1', 'arg2' );
>
> For catalog subs from catalog usertags:
>
> $Config->{Sub}{ name_of_sub }->( 'arg1', 'arg2' );
>
Those look correct to me. You'll need to test the Sub before you
use it, as follows:
my $sub = $Config->{sub}->{name_of_sub};
$sub->('arg1','arg2') if ref($sub) eq 'CODE';
There's also $Vend::Cfg->{Sub}->{subname} which, if memory serves,
is the same as $Config->{Sub}->{subname}, but for use in a global
UserTag.
In a global UserTag, you could allow a local Sub to override a GlobalSub
as follows:
my $sub = $Vend::Cfg->{Sub}->{subname} || $Global::GlobalSub->{subname};
$sub->('arg1','arg2') if ref($sub) eq 'CODE';
--
_/ _/ _/_/_/_/ _/ _/ _/_/_/ _/ _/
_/_/_/ _/_/ _/ _/ _/ _/_/ _/ K e v i n W a l s h
_/ _/ _/ _/ _/ _/ _/ _/_/ kevin at cursor.biz
_/ _/ _/_/_/_/ _/ _/_/_/ _/ _/
More information about the interchange-users
mailing list