Index  Up  <<  >>  


Sub

Defines a catalog subroutine for use by the [perl sub] subname arg [/perl] construct. Use the ``here document'' capability of MiniVend configuration files to make it easy to define:

    Sub <<EOF

    sub sort_cart {
        my(%items) = @_;
        my($item,$name);
        my $out = '&ltTABLE BORDER=1>';
        foreach $name (sort keys %items) {
            $out .= '&lt;TR>&lt;TD>';
            $out .= $items{$name};
            $out .= '&lt;/TD>&lt;TD>';
            $out .= $name;
            $out .= '&lt;/TD>&lt;/TR>';
        }
        $out .= '&lt/TABLE>';
        return $out;
    }
    EOF

As with Perl ``here documents'', the EOF (or other end marker) must be the ONLY thing on the line, with no leading or trailing white space. Do not append a semicolon to the marker.

The above would be called with:

    [perl sub]
        sort_cart ( [item-list]
                        "[item-description]", "[item-code]",
                    [/item-list] )
    [/perl]

and will display an HTML table of the items in the current shopping cart, sorted by the description. (Using an alternative form of quoting such as q{ } will minimize problems with quotes in the passed parameters -- you may use any style you like, including here documents. Syntax errors will be reported to error.log.)

Catalog subroutines may not perform unsafe operations -- the Safe.pm module enforces this.

Index  Up  <<  >>