.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "CGI::Application::Plugin::MessageStack 3pm" .TH CGI::Application::Plugin::MessageStack 3pm "2022-12-12" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" CGI::Application::Plugin::MessageStack \- A message stack for your CGI::Application .SH "VERSION" .IX Header "VERSION" Version 0.34 .SH "SYNOPSIS" .IX Header "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. .PP .Vb 2 \& use CGI::Application::Plugin::Session; \& use CGI::Application::Plugin::MessageStack; \& \& sub mainpage { \& my $self = shift; \& my $template = $self\->load_tmpl( \*(Aqmainpage.TMPL\*(Aq, \*(Aqdie_on_bad_params\*(Aq => 0 ); \& # ... \& $template\->output; \& } \& \& sub process { \& my $self = shift; \& $self\->push_message( \& \-scope => \*(Aqmainpage\*(Aq, \& \-message => \*(AqYour listing has been updated\*(Aq, \& \-classification => \*(AqINFO\*(Aq, \& ); \& $self\->forward( \*(Aqmainpage\*(Aq ); \& } \& \& sub cgiapp_init { \& # setup your session object as usual... \& } .Ve .PP Meanwhile, in your (HTML::Template) template code: .PP .Vb 10 \& ... \& \& ... \&

Howdy!

\& \&
"> \& \&
\& \& ... .Ve .PP 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. .PP Here's a quick \s-1TT\s0 example: .PP .Vb 10 \& \& ... \&

Howdy!

\& [% FOREACH CAP_Messages %] \&
[% message %]
\& [% END %] \& ... .Ve .PP If you use \s-1TT, I\s0 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 \s-1TT\s0 with the relevant messages. Your runmode could be this simple: .PP .Vb 5 \& sub start { \& my $self = shift; \& my $session = $self\->session; \& return $self\->tt_process( \*(Aqoutput.tt\*(Aq ); \& } .Ve .PP 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'. .PP \&\s-1NOTE: I\s0 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 \f(CW\*(C`\-loop_param_name\*(C'\fR. .SH "DESCRIPTION" .IX Header "DESCRIPTION" This plugin by default needs a session object to tuck away the message(s). It's recommended that you use this in conjunction with CGI::Application::Plugin::Session. You can opt to not have the messages persist and thereby, not use CAP-Session by using the \f(CW\*(C`\-dont_use_session\*(C'\fR option in the \f(CW\*(C`capms_config\*(C'\fR method. .PP 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. .PP In the functions, there are scope & classification keys and when they're used for either display or your \s-1API\s0 purposes (clearing, pop'ing, etc), the classification is an exclusive specification. Meaning, if you ask for messages with the '\s-1ERROR\s0' classification, it will only deal with messages that you've pushed in with the '\s-1ERROR\s0' classification. Any messages that have no classification aren't included. .PP The scope key is not exclusive, meaning that if you ask for messages with a 'mainpage' scope, it will deal with messages that you've pushed with that scope \fBas well as\fR any messages that you've pushed in without a scope. .PP If you use both scope & classification, it blends both of those rules, first getting all matching messages with the same classification and then filtering out messages that are scoped and don't match the scope you're looking for. .PP This logic may change as I get feedback from more saavy developers. What we may end up doing is have a plugin configuration where you can dictate the logic that's used. .SH "FUNCTIONS" .IX Header "FUNCTIONS" .SS "push_message" .IX Subsection "push_message" .Vb 5 \& $self\->push_message( \& \-scope => \*(Aqmainpage\*(Aq, \& \-message => \*(AqYour listing has been updated\*(Aq, \& \-classification => \*(AqINFO\*(Aq, \& ); .Ve .PP You provide a hash to the \fBpush_message()\fR method with three possible keys: .IP "\(bu" 4 message \- a text message. You can put \s-1HTML\s0 in there \- just make sure you don't use the ESCAPE=HTML in your HTML::Template code .IP "\(bu" 4 scope \- which runmode(s) can this message appear? If you want to specify just one, use a scalar assignment. Otherwise, use an array reference with the list of runmodes. .IP "\(bu" 4 classification \- a simple scalar name representing the classification of your message (i.e. '\s-1ERROR\s0', '\s-1WARNING\s0' ... ). This is very useful for \s-1CSS\s0 styles (see template example above). .PP The scope & classification keys are optional. If you don't provide a scope, it will assume a global presence. .SS "messages" .IX Subsection "messages" .Vb 4 \& my @messages = $self\->messages(); \& my @messages = $self\->messages( \-scope => \*(Aqmainpage\*(Aq ); \& my @messages = $self\->messages( \-scope => \*(Aqmainpage\*(Aq, \-classification => \*(AqERROR\*(Aq ); \& my @messages = $self\->messages( \-classification => \*(AqERROR\*(Aq ); .Ve .PP If you want to take a gander at the message stack data structure, you can use this method. .PP Optionally, you can use a hash parameters to get a slice of the messages, using the same keys as specified in the \fBpush_message()\fR method. .PP It will return an array reference of the matching messages or 'undef', if there's either no messages in the stack or no messages that match your specification(s). .SS "pop_message" .IX Subsection "pop_message" .Vb 4 \& my $message = $self\->pop_message(); \& my $message = $self\->pop_message( \-scope => \*(Aqmainpage\*(Aq ); \& my $message = $self\->pop_message( \-scope => \*(Aqmainpage\*(Aq, \-classification => \*(AqWARNING\*(Aq ); \& my $message = $self\->pop_message( \-classification => \*(AqERROR\*(Aq ); .Ve .PP Pops off the last message from the stack and returns it. Note that this just returns the \-message part. .PP You can pop off an exact message, given a hash parameters, using the same keys as specified in the \fBpush_message()\fR method. .PP Otherwise, it will pop off the message, given the current runmode and the last message added. .SS "clear_messages" .IX Subsection "clear_messages" .Vb 4 \& $self\->clear_messages(); \& $self\->clear_messages( \-scope => \*(Aqmainpage\*(Aq ); \& $self\->clear_messages( \-scope => \*(Aqmainpage\*(Aq, \-classification => \*(AqERROR\*(Aq ); \& $self\->clear_messages( \-classification => \*(AqERROR\*(Aq ); .Ve .PP Clears the message stack. .PP Optionally, you can clear particular slices of the message stack, given a hash parameters, using the same keys as specified in the \fBpush_message()\fR method. .PP If you specify a scope, it will clear any messages that are either global or match that scope .PP If you specify a classification, it will clear any messages that have that classification (but not any messages that don't have any classification). .PP If you specify both, it will combine both that logic in an \s-1AND\s0 fashion. .SS "capms_config" .IX Subsection "capms_config" .Vb 7 \& $self\->capms_config( \& \-automatic_clearing => 1, \& \-dont_use_session => 1, \& \-loop_param_name => \*(AqMyOwnLoopName\*(Aq, \& \-message_param_name => \*(AqMyOwnMessageName\*(Aq, \& \-classification_param_name => \*(AqMyOwnClassificationName\*(Aq, \& ); .Ve .PP There is a configuration option that you, as the developer can specify: .IP "\(bu" 4 \&\-automatic_clearing: By default, this is turned off. If you override it with a true value, it will call \fBclear_messages()\fR automatically after the messages are automatically put into template. .IP "\(bu" 4 \&\-dont_use_session: This will override this Plugin's dependence on CGI::Application::Plugin::Session and instead, temporarily store the message data such that it will be available to templates within the same web request, but no further. If you're running your cgiapp under a persistent state (mod_perl), we'll also make sure your messages are gone by the end of the request. .IP "\(bu" 4 \&\-loop_param_name: This will override the default _\|_CAP_Messages (or CAP_Messages for \s-1TT\s0 users) name for the loop of messages, which is only used for the \f(CW\*(C`load_tmpl\*(C'\fR callback. Meaning, this configuration will only impact your template code. So if you use the 'MyOwnLoopName' above, then your template code (for HTML::Template users) should look like: .Sp .Vb 3 \& \& ... \& .Ve .IP "\(bu" 4 \&\-message_param_name: This will override the default '\-message' in both the template code \fBas well as\fR the keys in each hashref of the arrayref that's returned by the \fBmessages()\fR function. So a call to \fBmessages()\fR may return: .Sp .Vb 1 \& [ { \*(AqMyOwnMessageName\*(Aq => \*(Aqthis is just a test\*(Aq }, ... ] .Ve .Sp instead of: .Sp .Vb 1 \& [ { \*(Aq\-message\*(Aq => \*(Aqthis is just a test\*(Aq }, ... ] .Ve .Sp Likewise, your templates will need to use your parameter name: .Sp .Vb 3 \& \& Here\*(Aqs the message: \& .Ve .IP "\(bu" 4 \&\-classification_param_name: Just like the \f(CW\*(C`\-message_param_name\*(C'\fR parameter \- this will override the default '\-classification' key in both the template code \fBas well as\fR the keys in each hashref of the arrayref that's returned by the \fBmessages()\fR function. So a call to \fBmessages()\fR may return: .Sp .Vb 1 \& [ { \*(AqMyOwnClassificationName\*(Aq => \*(AqERROR\*(Aq, \*(AqMyOwnMessageName\*(Aq => \*(Aqthis is just a test\*(Aq }, ... ] .Ve .Sp instead of: .Sp .Vb 1 \& [ { \*(Aq\-classification\*(Aq => \*(AqERROR\*(Aq, \*(Aq\-message\*(Aq => \*(Aqthis is just a test\*(Aq }, ... ] .Ve .Sp Likewise, your templates will need to use your parameter name: .Sp .Vb 5 \& \&
"> \& Here\*(Aqs the message: \&
\& .Ve .SH "AUTHOR" .IX Header "AUTHOR" Jason Purdy, \f(CW\*(C`\*(C'\fR .SH "SEE ALSO" .IX Header "SEE ALSO" CGI::Application and CGI::Application::Plugin::Session .SH "BUGS" .IX Header "BUGS" Please report any bugs or feature requests to \&\f(CW\*(C`bug\-cgi\-application\-plugin\-messagestack@rt.cpan.org\*(C'\fR, or through the web interface at . I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. .PP I suspect that this code could use some expert guidance. I hacked it together and I'd hate to think that it would be responsible for slowing templates down. Please feel free to submit patches, guiding comments, etc. .SH "ACKNOWLEDGEMENTS" .IX Header "ACKNOWLEDGEMENTS" Thanks to the guys on the #cgiapp channel .SH "COPYRIGHT & LICENSE" .IX Header "COPYRIGHT & LICENSE" Copyright 2005 Jason Purdy, all rights reserved. .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.