Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
62 lines (51 sloc) 1.57 KB
__NAME__ purpose
define global Perl functions for use within Interchange
__END__
__NAME__ see also
CodeDef,Sub,AllowGlobal
__END__
__NAME__ synopsis
<arg choice='plain'>
<literal>Sub</literal>
<replaceable>perl_code</replaceable>
</arg>
__END__
__NAME__ description
Define a global subroutine for use within &tag-perl;, &tag-mvasp;, or
embedded &PERL; languages.
</para><para>
The use of "here document" syntax in &IC; makes subroutine definitions
visually convenient.
__END__
__NAME__ example: Defining a global subroutine
<programlisting><![CDATA[
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
]]></programlisting>
The above code would be called from an &IC; page in the following way:
<programlisting><![CDATA[
[perl tables=products subs='count_orders']
return count_orders();
[/perl]
]]></programlisting>
__END__
__NAME__ notes
As with &PERL; "here documents," the "<literal>EOF</literal>" (or arbitrarily
named end marker) must be the <emphasis>only</emphasis> 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;).
</para><para>
Global subroutines are not subject to <classname>Safe</classname> security
checks. They can do most anything!
Therefore, &glos-scratch; or catalog subroutines (&conf-Sub;s) are
preferred in most cases to protect the innocent.
__END__
__NAME__ missing
Example isn't working? Sub gets called, but doesn't sort!
PORT_OLD
__END__
Jump to Line
Something went wrong with that request. Please try again.