App::TemplateServer - application to serve processed templates
template-server --docroot project/templates --data project/test_data.yml
Occasionally you need to give HTML templates to someone to edit without setting up a full perl environment for them. You can use this application to serve templates to the browser and provide those templates with sample data to operate on. The template editor will need Perl, but not a database, Apache, Catalyst, etc. (You can build a PAR and then they won't need Perl either.)
It's also useful for experimenting with new templating engines. You can start writing templates right away, without having to setup Apache or a Catalyst application first. Interfacing App::TemplateServer to a new templating system is a quick matter of writing a few lines of code. (See App::TemplateServer::Provider for details.)
App::TemplateServer
As a user, you'll be interacting with App::TemplateServer via the included template-server script.
template-server
Start the server. This method never returns.
The port to bind the server to. Defaults to 4000.
The directory containing templates. Defaults to the current directory.
The class name of the Provider to use. Defaults to App::TemplateServer::Provider::TT, but you can get others from the CPAN (for using templating systems other than TT).
App::TemplateServer::Provider::TT
As of version 0.02, you can omit the App::TemplateServer::Provider:: prefix if you prefer. The literal class you pass will be loaded first; if that fails then the App::TemplateServer::Provider:: prefix is added. Failing that, an exception is thrown.
App::TemplateServer::Provider::
The YAML file containing the package and variable definitions. For example:
--- foo: "bar" packages: Test: constructors: ["new"] methods: map_foo_bar: - ["foo"] - "bar" - ["bar"] - "foo" - "INVALID INPUT" instantiate: test_instance: "Test" another_test_instance: Test: "new"
This makes the variables foo, test_instance, and another_test_instance available in the templates. It also creates a package called Test and adds a constructor called new, and a method called map_foo_bar that returns "bar" when the argument is "foo", "foo" when the argument is "bar", and "INVALID INPUT" otherwise.
foo
test_instance
another_test_instance
Test
new
map_foo_bar
Any key/value pair other than packages and instantiate is treated as a literal variable to make available in the template.
packages
instantiate
packages is passed to Package::FromData and is used to dynamically create data, methods, static methods, and constructors inside packages. See Package::FromData for more details.
instantiate is a list of variables to populate with instantiated classes. The key is the variable name, the value is either a class name to call new on, or a hash containing a single key/value pair which is treated like class => method. This allows you to use the constructors that Package::FromData made for you.
class => method
Jonathan Rockway <jrockway@cpan.org>
<jrockway@cpan.org>
Copyright (c) 2008 Jonathan Rockway. You may redistribute this module under the same terms as Perl itself.
To install App::TemplateServer, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::TemplateServer
CPAN shell
perl -MCPAN -e shell install App::TemplateServer
For more information on module installation, please visit the detailed CPAN module installation guide.