CGI::Application::Plugin::MessageStack is a message stack for your CGI::Application.
SYNOPSIS
This plugin gives you a few support methods that you can call within your cgiapp to pass along messages between requests for a given user.
use CGI::Application::Plugin::Session;
use CGI::Application::Plugin::MessageStack;
sub mainpage {
my $self = shift;
my $template = $self- >load_tmpl( 'mainpage.TMPL', 'die_on_bad_params' = > 0 );
# ...
$template- >output;
}
sub process {
my $self = shift;
$self- >push_message(
-scope = > 'mainpage',
-message = > 'Your listing has been updated',
-classification = > 'INFO',
);
$self- >forward( 'mainpage' );
}
sub cgiapp_init {
# setup your session object as usual...
}
Meanwhile, in your (HTML::Template) template code:
...
< style type="text/css" >
.INFO {
font-weight: bold;
}
.ERROR {
color: red;
}
< /style >
...
< h1 >Howdy!< /h1 >
< !-- TMPL_LOOP NAME="CAP_Messages" -- >
< div class="< !-- TMPL_VAR NAME="classification" -- >" >
< !-- TMPL_VAR NAME="message" -- >
< /div >
< !-- /TMPL_LOOP -- >
...
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.
Here's a quick TT example:
< style type="text/css" >
.INFO {
font-weight: bold;
}
.ERROR {
color: red;
}
< /style >
...
< h1 >Howdy!< /h1 >
[% FOREACH CAP_Messages %]
< div class="[% classification %]" >[% message %]< /div >
[% END %]
...
If you use TT, I recommend using CAP-TT and a more recent version (0.09), which supports cgiapp's load_tmpl hook and then this plugin will automatically supply TT with the relevant messages. Your runmode could be this simple:
sub start {
my $self = shift;
my $session = $self- >session;
return $self- >tt_process( 'output.tt' );
}
I don't have the experience to weigh in on how you'd do this with other templates (HTDot, Petal), but basically, this plugin will put in a loop parameter called 'CAP_Messages'. Within each element of that loop, you'll have two tags, 'classification' and 'message'.
NOTE: I have broken backwards compatibility with this release (0.30) and the loop parameter's default name is now 'CAP_Messages'. If you used the old __CAP_Messages or want to use another name, feel free to use the capms_config to override the -loop_param_name.
Product's homepage
Requirements:
· Perl