GlobalSub — define global Perl functions for use within Interchange
Define a global subroutine for use within [perl]
, [mvasp]
, or
embedded Perl languages.
The use of "here document" syntax in Interchange makes subroutine definitions visually convenient.
Example: Defining a global subroutine
GlobalSub <<EOF sub count_orders { my $counter = new File::CounterFile "tmp/count_orders", '1'; my $number = $counter->inc(); return "There have been $number orders placed.\n"; } EOF
The above code would be called from an Interchange page in the following way:
[perl tables=products subs='count_orders'] return count_orders(); [/perl]
As with Perl "here documents," the "EOF
" (or arbitrarily
named end marker) must be the only thing on the line,
without leading or trailing white space. Also, do not append a semicolon to the
opening marker (as you would in Perl).
Global subroutines are not subject to Safe
security
checks. They can do most anything!
Therefore, scratch or catalog subroutines (Sub
s) are
preferred in most cases to protect the innocent.