Template::Provider::HTTP - fetch templates from a webserver
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 );
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"
Currently there is NO caching, so the webserver will get multiple hits every time that a template is requested. Patches welcome.
This module is a very thin layer on top of Template::Provider - please see the documentation there for full details.
Does some setup. Notably goes through the INCLUDE_PATH and removes anything that does not start with http.
INCLUDE_PATH
http
Returns a LWP::UserAgent object, or a cached one if it has already been called.
Returns the current time if the request is a success, otherwise undef. Could be smartened up with a bt of local caching.
Returns the content from the request, or an error.
Template::Provider - which this module inherits from.
This code is hosted on GitHub:
code: https://github.com/evdb/template-provider-http
bugs: https://github.com/evdb/template-provider-http/issues
Edmund von der Burg <evdb@ecclestoad.co.uk>
<evdb@ecclestoad.co.uk
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>.
ABSOLUTE =
TT3 - there has to be a better way than this :)
Sam as Perl.
To install Template::Provider::HTTP, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Template::Provider::HTTP
CPAN shell
perl -MCPAN -e shell install Template::Provider::HTTP
For more information on module installation, please visit the detailed CPAN module installation guide.