3 |
3 |
use strict;
|
4 |
4 |
|
5 |
5 |
require Exporter;
|
6 |
|
our @ISA = qw(Exporter);
|
7 |
|
our @EXPORT = qw(flash render_flash);
|
|
6 |
our @ISA = qw(Exporter);
|
|
7 |
our @EXPORT = qw(flash flash_later);
|
|
8 |
our @EXPORT_OK = qw(render_flash);
|
|
9 |
|
|
10 |
#
|
|
11 |
# public functions
|
|
12 |
#
|
8 |
13 |
|
9 |
14 |
sub flash {
|
10 |
|
my $category = shift;
|
11 |
|
$category = 'info' if $category eq 'information';
|
|
15 |
$::form->{FLASH} = _store_flash($::form->{FLASH}, @_);
|
|
16 |
}
|
12 |
17 |
|
13 |
|
$::form->{FLASH} ||= { };
|
14 |
|
$::form->{FLASH}->{ $category } ||= [ ];
|
15 |
|
push @{ $::form->{FLASH}->{ $category } }, @_;
|
|
18 |
sub flash_later {
|
|
19 |
$::auth->set_session_value(FLASH => _store_flash($::auth->get_session_value('FLASH'), @_))->save_session();
|
16 |
20 |
}
|
17 |
21 |
|
18 |
22 |
sub render_flash {
|
19 |
23 |
return $::form->parse_html_template('common/flash');
|
20 |
24 |
}
|
21 |
25 |
|
|
26 |
#
|
|
27 |
# private functions
|
|
28 |
#
|
|
29 |
|
|
30 |
sub _store_flash {
|
|
31 |
my $store = shift || { };
|
|
32 |
my $category = shift;
|
|
33 |
$category = 'info' if $category eq 'information';
|
|
34 |
|
|
35 |
$store ||= { };
|
|
36 |
$store->{ $category } ||= [ ];
|
|
37 |
push @{ $store->{ $category } }, @_;
|
|
38 |
|
|
39 |
return $store;
|
|
40 |
}
|
|
41 |
|
22 |
42 |
1;
|
23 |
43 |
|
24 |
44 |
__END__
|
... | ... | |
42 |
62 |
|
43 |
63 |
[%- INCLUDE 'common/flash.html' %]
|
44 |
64 |
|
|
65 |
=head1 EXPORTS
|
|
66 |
|
|
67 |
The functions L</flash> and L</flash_later> are always exported.
|
|
68 |
|
|
69 |
The function L</render_flash> is only exported upon request.
|
|
70 |
|
45 |
71 |
=head1 FUNCTIONS
|
46 |
72 |
|
47 |
73 |
=over 4
|
48 |
74 |
|
49 |
|
=item C<flash $category, $message>
|
|
75 |
=item C<flash $category, @messages>
|
50 |
76 |
|
51 |
|
Stores a message for the given category. The category can be either
|
|
77 |
Stores messages for the given category. The category can be either
|
52 |
78 |
C<information>, C<warning> or C<error>. C<info> can also be used as an
|
53 |
79 |
alias for C<information>.
|
54 |
80 |
|
|
81 |
=item C<flash_later $category, @messages>
|
|
82 |
|
|
83 |
Stores messages for the given category for the next request. The
|
|
84 |
category can be either C<information>, C<warning> or C<error>. C<info>
|
|
85 |
can also be used as an alias for C<information>.
|
|
86 |
|
|
87 |
The messages are stored in the user's session and restored upon the
|
|
88 |
next request. Can be used for transmitting information over HTTP
|
|
89 |
redirects.
|
|
90 |
|
55 |
91 |
=item C<render_flash>
|
56 |
92 |
|
57 |
93 |
Outputs the flash message by parsing the C<common/flash.html> template
|
58 |
94 |
file.
|
59 |
95 |
|
|
96 |
This function is not exported by default.
|
|
97 |
|
60 |
98 |
=back
|
61 |
99 |
|
62 |
100 |
=head1 AUTHOR
|
flash_later(): In Session gespeicherter Flash für nächsten Request implementiert