Name

GlobalSub — define global Perl functions for use within Interchange

SYNOPSIS

Sub perl_code

DESCRIPTION

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.

DIRECTIVE TYPE AND DEFAULT VALUE

Global directive

EXAMPLES

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]

NOTES

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 (Subs) are preferred in most cases to protect the innocent.

AVAILABILITY

GlobalSub is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: lib/Vend/Config.pm
Line 469

['GlobalSub',     'subroutine',       ''],

AUTHORS

Interchange Development Group

SEE ALSO

AllowGlobal(7ic), Sub(7ic), CodeDef(7ic)

DocBook! Interchange!