Skip Menu |

This queue is for tickets about the CGI-Application-Plugin-FormState CPAN distribution.

Report information
The Basics
Id: 50076
Status: stalled
Priority: 0/
Queue: CGI-Application-Plugin-FormState

People
Owner: Nobody in particular
Requestors: asb_ehb [...] yahoo.de
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.12
Fixed in: (no value)



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
I agree with the problem, but the solution is actually quite complicated, and is not solved by the patch. I have an experimental version on github, which is based on your patch: http://github.com/mgraham/CAP-FormState/tree/v0.12_1 The problem is that both CGI::Application::Plugin::AnyTemplate and CGI::Application::Plugin::TT call the load_tmpl hook. Neither of them set the new CGI::Application tmpl_class attribute. So there's no way for the load_tmpl hook to know that it should not treat the template file as an HTML::Template file. This would not be a problem if we could just detect the existence of the die_on_bad_params parameter. But we can't, since the *absense* of this parameter indicates that die_on_bad_params should be active. There are two options at this point: 1) Submit bug reports to CAP-AnyTemplate and CAP-TT, and any other template plugins, asking the authors to set tmpl_class before calling the load_tmpl hook. 2) Abandon this approach and provide a ht_die_on_bad_params config parameter to FormState itself. The first option seems more elegant, but is probably more fragile and hard to implement. The second option is quicker and dirtier, but more likely to happen quickly. Michael
Version 0.12_2 on github has a failing test case when using CAP::TT: http://github.com/mgraham/CAP-FormState/tree/v0.12_2
There's a discussion on the cgiapp mailinglist that needs resolution before we can close this ticket: http://www.erlbaum.net/pipermail/cgiapp/2009q4/001776.html