[cgiapp] proposal for new cgiapp hook: loaded_html_tmpl
Michael Graham
magog at the-wire.com
Fri Oct 23 17:21:09 EDT 2009
Here's a new proposal for solving the multiple template parsing problem
when die_on_bad_params is enabled. Add another callback to
CGI::Application:
loaded_html_tmpl
This gets called with the newly created template object before it gets
returned to the user. CAP::AnyTemplate and CAP::TT would not call this
hook.
Plugins wishing to automatically pass variables to templates would do
the following:
* hook the 'load_tmpl' callback
- if html_tmpl_class isa 'HTML::Template' then return.
- Otherwise, add parameters to $tmpl_params
* hook the 'loaded_html_template' callback
- return unless html_tmpl_class isa 'HTML::Template'
- check $ht_params for die_on_bad_params (default to 1)
- if die_on_bad_params is enabled, use HTML::Template's query method
to determine whether or not it is safe to add the parameter.
- if it is safe, add the parameter via $tmpl->param();
I don't know how many people use die_on_bad_params, so I don't
know how worth it it is to modify the core.
However, this hook would improve performance for users of
die_on_bad_params when using plugins that automatically add
template values, and it would greatly simplify the code required in
each of these plugins.
Michael
--
Michael Graham <magog at the-wire.com>
More information about the cgiapp
mailing list