Skip to content
Newer
Older
100644 118 lines (72 sloc) 2.87 KB
91cbc9f @dams readme -> readme.pod
authored
1 =pod
2
3 =head1 NAME
4
5 Dancer::Plugin::FlashMessage - A plugin to display "flash messages" : short temporary messages
6
7 =head1 SYNOPSYS
8
9 Example with Template Toolkit: in your index.tt view or in your layout :
10
11 <% IF flash.error %>
12 <div class=error> <% flash.error %> </div>
13 <% END %>
14
15 In your css :
b01058a @dams pod fix
authored
16
91cbc9f @dams readme -> readme.pod
authored
17 .error { background: #CEE5F5; padding: 0.5em;
18 border: 1px solid #AACBE2; }
19
20 In your Dancer App :
21
22 package MyWebService;
23
24 use Dancer;
25 use Dancer::Plugin::FlashMessage;
26
27 get '/hello' => sub {
28 flash error => 'Error message';
29 template 'index';
30 };
31
32 =head1 DESCRIPTION
33
34 This plugin helps you display temporary messages, so called "flash messages".
b298a76 @dams pod fix
authored
35 It provides a C<flash()> method to define the message. The plugin then takes
36 care of attaching the content to the session, propagating it to the templating
37 system, and then removing it from the session.
91cbc9f @dams readme -> readme.pod
authored
38
39 However, it's up to you to have a place in your views or layout where the
40 message will be displayed. But that's not too hard (see L<SYNOPSYS>).
41
42 Basically, the plugin gives you access to the 'flash' hash in your views. It
43 can be used to display flash messages.
44
45 By default, the plugin works using a descent default configuration. However,
46 you can change the behaviour of the plugin. See L<CONFIGURATION>
47
48 =head1 METHODS
49
50 =head2 flash
51
b01058a @dams pod fix
authored
52 # sets the flash message for the warning key
53 flash warning => 'some warning message';
91cbc9f @dams readme -> readme.pod
authored
54
b01058a @dams pod fix
authored
55 # retrieves and removes the flash message for the warning key
56 my $warning_message = flash 'warning';
91cbc9f @dams readme -> readme.pod
authored
57
58 This method can take 1 or 2 parameters. When called with two parameters, it
59 sets the flash message for the given key.
60
61 When called with one parameter, it returns the value of the flash message of
62 the given key, and also deletes this entry.
63
64 In both cases, C<flash> always returns the value;
65
66 =head1 CONFIGURATION
67
68 =head2 no configuration
69
70 With no configuration whatsoever, the plugin will work fine, thus contributing
71 to the I<keep it simple> motto of Dancer.
72
73 =head2 configuration default
74
75 These are the default values. See below for a description of the keys
76
77 plugins:
78 FlashMessage:
79 token_name: flash
80 session_hash_key: _flash
81
82 =head2 configuration description
83
84 =over
85
86 =item token_name
87
b298a76 @dams pod fix
authored
88 The name of the template token that will contain the hash of flash messages.
89 Default : flash
91cbc9f @dams readme -> readme.pod
authored
90
91 =item session_hash_key
92
93 You probably don't need that, but this setting allows you to change the name of
b298a76 @dams pod fix
authored
94 the session key used to store the hash of flash messages. It may be useful in
95 the unlikely case where you have key name conflicts in your session. Default :
96 _flash
91cbc9f @dams readme -> readme.pod
authored
97
98 =back
99
3fd58f3 @dams fix readme and pod
authored
100 =head1 COPYRIGHT
101
102 This software is copyright (c) 2011 by Damien "dams" Krotkine.
103
91cbc9f @dams readme -> readme.pod
authored
104 =head1 LICENCE
105
3fd58f3 @dams fix readme and pod
authored
106 This is free software; you can redistribute it and/or modify it under
107 the same terms as the Perl 5 programming language system itself.
91cbc9f @dams readme -> readme.pod
authored
108
109 =head1 AUTHORS
110
111 This module has been written by Damien Krotkine <dams@cpan.org>.
112
113 =head1 SEE ALSO
114
115 L<Dancer>
116
117 =cut
Something went wrong with that request. Please try again.