|
(You are
Anonymous)
|
NAMECGI::Application::Plugin::MessageStack VERSION0.01 SYNOPSISuse CGI::Application::Plugin::Session;
use CGI::Application::Plugin::MessageStack;
sub mainpage {
my $self = shift;
my $template = $self->load_tmpl( 'mainpage.TMPL' );
# ...
$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 -->
...
You're using Template::Toolkit? Ok: Cees? Using HTDot? Ok: HTDot is 100% backwards-compatible with regular HTML::Template, so see above :) -- RhesaRozendaal DESCRIPTIONThis plugin NEEDS a session object to tuck away the message(s). So please use this in conjunction with CGI::Application::Plugin::Session. This plugin hooks into cgiapp's load_tmpl method and if you've pushed any messages in the stack, will automatically add the message parameters. METHODSpush_message()$self->push_message(
-scope => 'mainpage',
-message => 'Your listing has been updated',
-classification => 'INFO',
);
You provide a hash to the push_message() method with three possible keys:
The scope & classification keys are optional. If you don't provide a scope, it will assume a global presence. messages()my @messages = $self->messages(); my @messages = $self->messages( -scope => 'mainpage' ); my @messages = $self->messages( -scope => 'mainpage', -classification => 'ERROR' ); my @messages = $self->messages( -classification => 'ERROR' ); If you want to take a gander at the message stack data structure, you can use this method. Optionally, you can use a hash parameters to get a slice of the messages, using the same keys as specified in the push_message() method. pop_message()my $message = $self->pop_message(); my $message = $self->pop_message( -scope => 'mainpage' ); my $message = $self->pop_message( -scope => 'mainpage', -classification => 'WARNING' ); my $message = $self->pop_message( -classification => 'ERROR' ); Pops off the last message from the stack and returns it. You can pop off an exact message, given a hash parameters, using the same keys as specified in the push_message() method. Otherwise, it will pop off the message, given the current runmode and the last message added. clear_messages()$self->clear_messages(); $self->clear_messages( -scope => 'mainpage' ); $self->clear_messages( -scope => 'mainpage', -classification => 'ERROR' ); $self->clear_messages( -classification => 'ERROR' ); Clears the message stack. This method will be called automatically when the Plugin puts it into your template. Optionally, you can clear particular slices of the message stack, given a hash parameters, using the same keys as specified in the push_message() method. AUTHORJason Purdy <Jason@Purdy.INFO> SEE ALSOCGI::Application CGI::Application::Plugin::Session ACKNOWLEDGEMENTSThanks to the guys on the #cgiapp channel! BUGSPlease report any bugs or feature requests to bug-cgi-application-plugin-messagestack@rt.cpan.org, or through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. COPYRIGHT & LICENSECopyright 2005 Jason Purdy, All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |