Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 4065042c

Von Moritz Bunkus vor fast 14 Jahren hinzugefügt

  • ID 4065042cd5d4e57afab40cfcf2074a6b4c7fd9c7
  • Vorgänger a7c70594
  • Nachfolger 22ef7f9a

flash_later(): In Session gespeicherter Flash für nächsten Request implementiert

Unterschiede anzeigen:

SL/Dispatcher.pm
170 170

  
171 171
      $::auth->set_session_value('login', $::form->{login}, 'password', $::form->{password});
172 172
      $::auth->create_or_refresh_session;
173
      $::auth->delete_session_value('FLASH')->save_session();
173 174
      delete $::form->{password};
174 175

  
175 176
      if ($action) {
SL/Helper/Flash.pm
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

Auch abrufbar als: Unified diff