GlobalSub
Define global Perl subroutines for use within Interchange.
Synopsis
|
GlobalSub sub { Perl code here }
|
Scope
This directive is only available for use in the global
(interchange.cfg) configuration file,
and will affect all websites running under the Interchange installation.
It will not work in a website's local (catalog.cfg)
configuration file.
Description
This directive defines a global subroutine for use by the
[perl] and [mvasp] tags.
Individual subroutines may be executed via the Perl
$Sub object.
|
Warning
These global subroutines are not subject to security checks;
They can do almost anything!
For most purposes, scratch subroutines or website-specific subroutines
(such as Sub) are better.
|
GlobalSub routines are subject to full Perl "use strict" checking,
so errors are possible if lexical variables or complete package
qualifications are not used for the variables.
Using the AdminSub directive,
a GlobalSub's visibility can be restricted to only websites
that have AllowGlobal privilege.
You should think very carefully before granting
AllowGlobal privilege to a website.
Example
GlobalSub <<EOG
sub count_orders {
my $counter = new File::CounterFile('tmp/count_orders','1');
my $number = $counter->inc();
return "$number order(s) have been placed.";
}
EOG
|
Just as with Perl "here documents",
the "EOG" (whatever name you use for your end marker) must be the only
text on the line,
with no leading or trailing white space.
Do not append a semicolon, or other character, to the marker.
The above GlobalSub could be called from an Interchange page in the
following manner, and with the following result:
Order count: [perl subs="count_orders"]
return count_orders();
[/perl]
|
|
Order count: 5 order(s) have been placed.
|