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

NAME

Template::Provider::HTTP - fetch templates from a webserver

Build status

SYNOPSIS

    use Template;
    use Template::Provider::HTTP;

    my %provider_config = (
        INCLUDE_PATH => [
            "/some/local/path",                        # file
            "http://svn.example.com/svn/templates/",    # url
        ],
    );

    my $tt = Template->new(
        {   LOAD_TEMPLATES => [
                Template::Provider::HTTP->new( \%provider_config ),
                Template::Provider->new( \%provider_config ),
            ],
        }
    );

    # now use $tt as normal
    $tt->process( 'my_template.html', \%vars );

DESCRIPTION

Templates usually live on disk, but this is not always ideal. This module lets you serve your templates over HTTP from a webserver.

For our purposes we wanted to access the latest templates from a Subversion repository and have them update immediately.

ABSOLUTE = 1 when passed to the constructor acts as a helper to support full path to your http template. "Full" path begins at the domain name(omit http://):

    use Template;
    use Template::Provider::HTTP;
    
    my $tt = Template->new( { LOAD_TEMPLATES => [
        Template::Provider::HTTP->new( ABSOLUTE => 1 ) ], } );
    $tt->process( 'www.example.com/templates/my_template.html', \%vars );

EXPAND_RELATIVE = 1 when passed to the constructor will attempt to expand relative paths in the source document into absolute paths. For example: href="../../main.css" will turn into: href="http://www.someurl.tld/some/path/../../main.css"

NOTE

Currently there is NO caching, so the webserver will get multiple hits every time that a template is requested. Patches welcome.

METHODS

This module is a very thin layer on top of Template::Provider - please see the documentation there for full details.

PRIVATE METHODS

_init

Does some setup. Notably goes through the INCLUDE_PATH and removes anything that does not start with http.

_ua

Returns a LWP::UserAgent object, or a cached one if it has already been called.

_template_modified

Returns the current time if the request is a success, otherwise undef. Could be smartened up with a bt of local caching.

_template_content

Returns the content from the request, or an error.

SEE ALSO

Template::Provider - which this module inherits from.

BUGS AND REPO

This code is hosted on GitHub:

code: https://github.com/evdb/template-provider-http

bugs: https://github.com/evdb/template-provider-http/issues

AUTHOR

Edmund von der Burg <evdb@ecclestoad.co.uk>

THANKS

Developed whilst working at Foxtons for an internal system there and released with their blessing.

Kevin Kane (https://github.com/klkane) added support for ABSOLUTE = 1>.

GOD SPEED

TT3 - there has to be a better way than this :)

LICENSE

Sam as Perl.