The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Template::Utils - Various utility functions for the Template Tookit.

SYNOPSIS

    use Template::Utils qw( :all );

    my $handler = output_handler($target);
    my $target  = update_hash(\%target, \%params, \%defaults)

DESCRIPTION

The Template::Utils module defines a number of general sub-routines used by the Template Toolkit. These can be called by explicitly prefixing the Template::Utils package name to the sub-routine, or by first importing the functions into the current package by passing the ':subs' or ':all' tagset names to the use Template::Utils line.

UTILITY SUB-ROUTINES

output_handler($target)

Creates a closure which can be called to send output to a particular target. The $target parameter may be an existing CODE ref (the ref is returned), a reference to a GLOB such as \*STDOUT (a closure which print to the GLOB is returned), a reference to an IO::Handle (a closure which calls the handle's print() method is returned) or a reference to a target string (a closure which appends output to the string is returned).

The closure returned will print all parameters passed to it, as per print().

    open(ERRLOG, "> $errorlog")
        || die "$errorlog: $!\n";

    my $fh = IO::File->new("> $myfile")
        || die "$myfile: $!\n";

    my $h1 = output_handler(\*STDERR);
    my $h2 = output_handler(\*ERRLOG);
    my $h3 = output_handler($fh);
    my $h4 = output_handler(\$mystring);

    foreach my $h ( $h1, $h2, h3, $h4 ) {
        &$h("An error has occured...\n");
    }

update_hash(\%target, \%params, \%defaults)

Updates the target hash referenced by the first paramter with values specified in the second. The third parameter may also reference a hash which is used to define the valid keys and default values.

A reference to the target hash ($target) is returned.

AUTHOR

Andy Wardley <cre.canon.co.uk>

REVISION

$Revision: 1.8 $

COPYRIGHT

Copyright (C) 1996-1999 Andy Wardley. All Rights Reserved. Copyright (C) 1998-1999 Canon Research Centre Europe Ltd.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

Template