1 package SL::Helper::Flash;
6 our @ISA = qw(Exporter);
7 our @EXPORT = qw(flash flash_later);
8 our @EXPORT_OK = qw(render_flash);
10 my %valid_categories = (
11 map({$_ => 'info'} qw(information message)),
12 map({$_ => $_} qw(info error warning)),
20 $::form->{FLASH} = _store_flash($::form->{FLASH}, @_);
24 $::auth->set_session_value({ key => "FLASH", value => _store_flash($::auth->get_session_value('FLASH'), @_), auto_restore => 1 });
28 return $::form->parse_html_template('common/flash');
36 my $store = shift || { };
37 my $category = _check_category(+shift);
40 $store->{ $category } ||= [ ];
41 push @{ $store->{ $category } }, @_;
48 return $valid_categories{$c}
51 croak("invalid category '$c' for flash");
61 SL::Helper::Flash - helper functions for storing messages to be
66 The flash is a store for messages that should be displayed to the
67 user. Each message has a category which is usually C<information>,
68 C<warning> or C<error>. The messages in each category are grouped and
69 displayed in colors appropriate for their severity (e.g. errors in
72 Messages are rendered either by calling the function C<render_flash>
73 or by including the flash sub-template from a template with the
76 [%- INCLUDE 'common/flash.html' %]
80 The functions L</flash> and L</flash_later> are always exported.
82 The function L</render_flash> is only exported upon request.
88 =item C<flash $category, @messages>
90 Stores messages for the given category. The category can be either
91 C<information>, C<warning> or C<error>. C<info> can also be used as an
92 alias for C<information>.
94 =item C<flash_later $category, @messages>
96 Stores messages for the given category for the next request. The
97 category can be either C<information>, C<warning> or C<error>. C<info>
98 can also be used as an alias for C<information>.
100 The messages are stored in the user's session and restored upon the
101 next request. Can be used for transmitting information over HTTP
104 =item C<render_flash>
106 Outputs the flash message by parsing the C<common/flash.html> template
109 This function is not exported by default.
115 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>