Subject: | [patch] support HTML::Template and die_on_bad_parameters => 1 |
Hi!
If using HTML::Template with (default) option die_on_bad_params => 1,
an error will raise for each template where CAP::FormState will try to
insert this TMPL_VAR $storage_name. It's is done by
_add_form_state_id_to_tmpl().
The following code will avoid this error by instatiating the template
in _add_form_state_id_to_tmpl() and query() it for a TMPL_VAR called
$storage_name. This way, the TMPL_VAR $storage_name is only set if it
is present - but only if html_tmpl_class() is HTML::Template.
# add the storage id to the template params
sub _add_form_state_id_to_tmpl {
my ($self, $ht_params, $tmpl_params, $tmpl_file) = @_;
my $storage_hash = $self->form_state->id;
my $storage_name = $self->form_state->name;
# -- check for HTML::Template and die_on_bad_params => 1
# TODO: omit check if die_on_bad_params => 0.
if( $self->html_tmpl_class() eq 'HTML::Template' ) {
my $t = undef;
# -- copied from CGI::Application::load_tmpl()
if( ref $tmpl_file eq 'SCALAR' ) {
$t = HTML::Template->new( scalarref => $tmpl_file,
%{$ht_params} );
} elsif ( ref $tmpl_file eq 'GLOB' ) {
$t = HTML::Template->new( filehandle => $tmpl_file,
%{$ht_params} );
} else {
$t = HTML::Template->new( filename => $tmpl_file,
%{$ht_params});
}
return unless $t->query(name => $storage_name);
}
$tmpl_params->{$storage_name} = $storage_hash;
}
Of course one could always choose to simply set die_on_bad_params => 0,
but I would dislike it, as the detection of missing / malformed
TMPL_VARs gets harder.
HTH, Alex