Name

Sub — define Perl functions for use within a catalog

SYNOPSIS

perl_code

DESCRIPTION

Define a catalog 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

Catalog directive

EXAMPLES

Example: Defining a subroutine

Sub <<EOF
sub sort_cart_by_quantity {
  my($items) = @_;
  $items = $Items if ! $items;

  my $out = '<table border="1">';

  @$items = sort { $a->{quantity} <=> $b->{quantity} } @$items;
  foreach $item (@$items) {
    my $code = $item->{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 .= '&lt/table>';
  return $out;
}
EOF

The above code would be called from an Interchange page in the following way:

Items, sorted by quantity:
[perl tables=products subs='sort_cart_by_quantity']
  my $cart = $Carts->{main};
  return sort_cart_by_quantity($cart);
[/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. Do not append a semicolon to the marker (as you would in Perl).

Catalog subroutines may not perform unsafe operations. The Safe module enforces this unless global operations are allowed for the catalog. See safe glossary entry for more information.

AVAILABILITY

Sub is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: lib/Vend/Config.pm
Line 575

['Sub',         'subroutine',       ''],

AUTHORS

Interchange Development Group

SEE ALSO

AllowGlobal(7ic), UserTag(7ic), CodeDef(7ic), GlobalSub(7ic)

DocBook! Interchange!