For more information... RTFM!
NAVIGATION
PAGES THAT LINK HERE
ACCOUNT LOGIN

You are not logged in

Powered by Interchange version 5.7.0

Sub

Define global Perl subroutines for use within Interchange.

Synopsis

Sub  sub { Perl code here }

Scope

This directive is only available for use in the local (catalog.cfg) configuration file.  It will not affect any other website in any way.  This directive will not work in the global (interchange.cfg) configuration file. 

Description

This directive can be used to define local website-specific subroutines for use by the [perl] and [mvasp] tags.  Individual subroutines may be executed via the Perl $Sub object.

Note

Note

Website-specific subroutines may not perform unsafe operations.  The

Safe Link to an external page module enforces this, unless the website is configured into the AllowGlobal list.

Syntax errors will be reported when the website is (re)started or reconfigured.

Example

Sub <<EOS
sub sort_cart_by_quantity {
    my $items = shift || $Items;

    my $out = '<table border="1">';
    foreach (sort { $a->{quantity} <=> $b->{quantity} } @$items) {
        my $code = $_->{code};

        $out .= '<tr><td>';
        $out .= $code;
        $out .= '</td><td>';
        $out .= $Tag->data('products','name',$code);
        $out .= '</td><td>';
        $out .= $Tag->data('products','price',$code);
        $out .= '</td></tr>';
    }
    $out .= '</table>';
    return $out;
}
EOS

Just as with Perl "here documents", the EOS (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 Sub could be called from an Interchange page in the following manner, which will display an HTML table of the items in the current shopping cart, sorted by the quantity:

Items, sorted by quantity:
[perl tables=products subs="sort_cart_by_quantity"]
    return sort_cart_by_quantity($Items);
[/perl]

Category:  Local config directives
Last modified by: Kevin Walsh
Modification date: Tuesday 20 March 2007 at 10:49 AM (EDT)
Home  |  Legal nonsense  |  Privacy policy  |  Donations  |  Contact us