NAME

Top Close Open

Template:TT3::Provider::Cwd - template provider for files in the current working directory

SYNOPSIS

Top Close Open
use Template::TT3::Provider::Cwd;

my $provider = Template::TT3::Provider::Cwd->new;

# all files are resolved relative to the current working directory
my $template = $provider->fetch('example.tt3')
    || die $provider->reason;

my $template = $provider->fetch('subdir/example.tt3')
    || die $provider->reason;

my $template = $provider->fetch('../../updir/example.tt3')
    || die $provider->reason;

DESCRIPTION

Top Close Open

This module is a subclass of Template::TT3::Provider for providing templates relative to the current working directory. It is the default provider used when no template_path option is defined.

METHODS

Top Close Open

This module implements the following methods in addition to, or replacing those inherited from the Template::TT3::Provider , Template::TT3::Base and Badger::Base base classes.

init()

Top Close Open

Custom initialisation method called by the new() constructor method inherited from Badger::Base . It does not accept any configuration parameters.

use Template::TT3::Provider::Cwd;

my $provider = Template::TT3::Provider::Cwd->new;

It uses the Cwd object to store the current working directory at that point in time. All template requests will be resolved relative to that directory.

fetch($uri)

Top Close Open

This method fetches a template from the filesystem identified by the $uri argument. This should be a regular file path, e.g. bar.tt3, /foo/bar.tt3, etc. Both relative and absolute paths are resolved with respect to the current working directory. Unlike the file provider , this does allow you to "navigate" outside of the current working directory.

my $template = $provider->fetch('example.tt3')
    || die $provider->reason;

my $template = $provider->fetch('subdir/example.tt3')
    || die $provider->reason;

my $template = $provider->fetch('../../updir/example.tt3')
    || die $provider->reason;

It returns a hash array containing a file item which references a Badger::Filesystem::File object and a uri indicating the definitive path (i.e. the absolute path, including the root directory of the virtual filesystem) of the template. e.g.

{
    file => $VFS->file('/local/path.tt3'),
    uri  => '/path/to/your/templates/two/local/path.tt3',
}

If the file cannot be found then the method returns undef, as per Template::TT3::Provider::File . If an error occurs then an exception will thrown.

AUTHOR

Top Close Open

Andy Wardley http://wardley.org

COPYRIGHT

Top Close Open

Copyright (C) 1996-2009 Andy Wardley. All Rights Reserved.

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


http://tt3.template-toolkit.org/docs/Template/TT3/Provider/Cwd.pm last modified 2009-12-23 11:34:48