Catalyst::View::TT::FunctionGenerator - Generate functions from ... to be used from a TT view
# running this: prompty_wompty> scripts/myapp_create.pl create view ViewName TT # generates a Template Toolkit view component. # change the base class like this: use base 'Catalyst::View::TT::FunctionGenerator'; # In a nearby action method (in Controller code) sub action : Local { my ( $self, $c ) = @_; $c->view("ViewName")->generate_functions('prototype'); # OR $c->view("ViewName")->generate_functions($c->prototype); # OR $c->view("ViewName")->generate_functions([$c, 'uri_for']); } # In your template, we can now have: [% link_to_remote("foo", { url => uri_for("blah") } ) %] # instead of saying this: [% c.prototype.link_to_remote("foo", { url => c.uri_for("blah") } ) %]
Note that the most appropriate place to put this code is probably in an end action at the top level of your application so that access to these functions in uniform accross your templates.
end
This module stuffs given methods as coderefs into your TT variables, enabling the use of shorter names in your templates. To use this plugin, you will need to be using the Singleton plugin as well (so that we only populate one correct copy of the context object).
To use, first create a Catalyst::View::TT module in the usual way (see synopsis), then change its base class to this module. To add the method shortcuts, call the generate_functions method in your controller code, in an action, before forwarding to your template.
This is the only available method. It's parameters are a list of one or more of the following:
An arrayref, where the first item in the array is either an object (e.g. what $c->prototype returns), or a method name that will return an object, when called upon $c, e.g. "prototype". The other array items are the method names of the given object that will be created as template vars.
$c->prototype
$c
An object (blessed reference). All methods found for the object will be created as template vars.
The method name will be called upon <$c>, and all methods for the resulting object will be added as template vars.
Catalyst::View::TT Catalyst::Plugin::Singleton
Yuval Kogman, nothingmuch@woobling.org
nothingmuch@woobling.org
Jess Robinson, Marcus Ramberg (POD)
Copyright (c) 2005 the aforementioned authors. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Catalyst::View::TT::FunctionGenerator, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Catalyst::View::TT::FunctionGenerator
CPAN shell
perl -MCPAN -e shell install Catalyst::View::TT::FunctionGenerator
For more information on module installation, please visit the detailed CPAN module installation guide.