Skip Menu |

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

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

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

Bug Information
Severity: Wishlist
Broken in: 0.34
Fixed in: (no value)



Subject: handle HTML::Template with die_on_bad_params => 1
Currently, "it's a good idea to turn off 'die_on_bad_params' in HTML::Template - in case this plugin tries to put in the parameters and they're not available in your template". Catching html_tmpl_class() would solve this problem. Here is my quick 'n dirty workaround. I set $self->param('__CAP_MessageStack_concering_templates') to a hashref of template names, where CAP::MessageStack should insert its values. [snip] sub cgiapp_init { $self->param('__CAP_MessageStack_concering_templates' => { '/path/to/template.tmpl' => 1, 'another_tmpl_file.tmpl' => 1, }); $self->capms_config( -automatic_clearing => 1, ); } package CAP::MessageStack; sub _pass_in_messages { my ( $self, $one, $tmpl_params, $template_file ) = @_; if( $self->html_tmpl_class() eq 'HTML::Template' ) { my $concerning_templates = $self->param('__CAP_MessageStack_concering_templates'); return unless defined $concerning_templates; return unless exists $concerning_templates->{$template_file}; } [/snip] A proper way of doing this would probably be the use of the capms_config method instead of param(). I imagine something like this: sub cgiapp_init { $self->param('__CAP_MessageStack_concering_templates' => { '/path/to/template.tmpl' => 1, 'another_tmpl_file.tmpl' => 1, }); $self->capms_config( -automatic_clearing => 1, -concering_templates => ['/path/to/template.tmpl','another_tmpl_file.tmpl'], ); }
I found a better approach to solve the problem of incopatibility with the default template engine of CGI::Application, which is HTML::Template. It catches the use of HTML::Template and only inserts the message_loop paramn, if it is actually defined in the current template. No need to declare extra option for CAP::MessageStack and the check isn't performed if there is another templating mechanism used. Please replace _pass_in_messages() with the following: sub _pass_in_messages { my ( $self, $ht_params, $tmpl_params, $tmpl_file ) = @_; my $loop_name = $config{'-loop_param_name'} || 'CAP_Messages'; # -- 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 => $loop_name); } # get the proper messages and update $tmpl_params my $session = _check_for_session( $self ); my $current_runmode = $self->get_current_runmode(); my $message_stack = $session->param( '__CAP_MessageStack_Stack' ); my $messages = _filter_messages( $message_stack, { -scope => $current_runmode }, 1 ); $tmpl_params->{ $loop_name } = $messages if scalar( @$messages ); $self->clear_messages( -scope => $current_runmode ) if ( $config{'-automatic_clearing'} ); }
ongoing discussion here: http://www.erlbaum.net/pipermail/cgiapp/2009q4/001737.html need to resolve that discussion before resolving this ticket