line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::Plugin::BootstrapAlert; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
15048
|
use 5.006; |
|
1
|
|
|
|
|
5
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
8
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
32
|
|
6
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
458
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Catalyst::Plugin::BootstrapAlert - Replacement for Catalyst::Plugin::StatusMessage inline with Bootstrap alert names (success, info, warning, and danger). |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Version 0.40 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '0.40'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Replacement for Catalyst::Plugin::StatusMessage using Bootstrap alert names (success, info, warning, and danger), |
25
|
|
|
|
|
|
|
whilst also keeping C and C as aliases. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
In MyApp.pm: |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
use Catalyst qr/ |
30
|
|
|
|
|
|
|
BootstrapAlert |
31
|
|
|
|
|
|
|
/; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
In controller where you want to save a message for display on the next page: |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$c->response->redirect( "/?mid=" . $c->set_success_alert("It worked!") ); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Or, to save an danger message: |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
$c->response->redirect( "/?mid=" . $c->set_error_msg("Error deleting widget") ); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Then, in the controller action that corresponds to the redirect above: |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub list :Path { |
44
|
|
|
|
|
|
|
my ($self, $c) = @_; |
45
|
|
|
|
|
|
|
... |
46
|
|
|
|
|
|
|
$c->load_bootstrap_alerts; |
47
|
|
|
|
|
|
|
... |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
This would mean simply changing C if using C. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
And, to display the output (here using L): |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
... |
55
|
|
|
|
|
|
|
[% success_alert %] |
56
|
|
|
|
|
|
|
[% error_msg %] |
57
|
|
|
|
|
|
|
... |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 METHODS |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 load_bootstrap_alerts |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Load all alerts that match the token parameter on the URL (e.g., |
64
|
|
|
|
|
|
|
http://example.com/dashboard?mid=1234567890) into the stash |
65
|
|
|
|
|
|
|
for display by the viewer. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
In general, you will want to include this in an C or "base" (if |
68
|
|
|
|
|
|
|
using Chained dispatch) controller action. Then, if you have a |
69
|
|
|
|
|
|
|
"template wrapper page" that displays "C", "C", |
70
|
|
|
|
|
|
|
"C", and "C", you can automatically and safely send status messages to |
71
|
|
|
|
|
|
|
any related controller action. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub load_bootstrap_alerts |
76
|
|
|
|
|
|
|
{ |
77
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my $config = $self->_plugin_bootstrap_alert_config; |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
0
|
|
|
|
my $param = $self->request->params->{ $config->{ alert_param } } || return; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
foreach my $type ( @{ $config->{ alert_types } } ) |
|
0
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
{ |
85
|
0
|
|
|
|
|
|
my $key = $type . '_alert_stash_key'; |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
$self->stash( $config->{ $key } => $self->_get_bootstrap_alert( $type, $param ) ); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# the aliases for Catalyst::Plugin::StatusMessage |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
my $alias_key = $type . '_alert_stash_key_alias'; |
92
|
|
|
|
|
|
|
|
93
|
0
|
0
|
|
|
|
|
if ( my $alias = $config->{ $alias_key } ) |
94
|
|
|
|
|
|
|
{ |
95
|
0
|
|
|
|
|
|
$self->stash( $alias => $self->stash->{ $config->{ $key } } ); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 set_success_alert |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Sets the success alert text. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
0
|
1
|
|
sub set_success_alert { return shift->_set_bootstrap_alert( 'success', shift ) } |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 set_info_alert |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Sets the info alert text. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=cut |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
0
|
1
|
|
sub set_info_alert { return shift->_set_bootstrap_alert( 'info', shift ) } |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 set_warning_alert |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Sets the warning alert text. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
0
|
1
|
|
sub set_warning_alert { return shift->_set_bootstrap_alert( 'warning', shift ) } |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 set_danger_alert |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Sets the danger alert text. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
0
|
1
|
|
sub set_danger_alert { return shift->_set_bootstrap_alert( 'danger', shift ) } |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 set_status_msg |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Sets the success alert text - this is an alias for when you're switching out Catalyst::Plugin::StatusMessage. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |
137
|
|
|
|
|
|
|
|
138
|
0
|
|
|
0
|
1
|
|
sub set_status_msg { return shift->set_success_alert( shift ) } |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head2 set_error_msg |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Sets the danger alert text - this is an alias for when you're switching out Catalyst::Plugin::StatusMessage. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=cut |
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
0
|
1
|
|
sub set_error_msg { return shift->set_danger_alert( shift ) } |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 CONFIGURABLE OPTIONS |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Here is a quick example showing how Catalyst::Plugin::BootstrapAlert |
151
|
|
|
|
|
|
|
can be configured: |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
# Configure Catalyst::Plugin::BootstrapAlert |
154
|
|
|
|
|
|
|
__PACKAGE__->config( |
155
|
|
|
|
|
|
|
'Plugin::BootstrapAlert' => { |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
session_key => 'my_status_msg', |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
alert_param => 'my_mid', |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
alert_types => [ qw( success info warning danger ) ], |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
success_alert_stash_key => 'success_alert', |
164
|
|
|
|
|
|
|
info_alert_stash_key => 'info_alert', |
165
|
|
|
|
|
|
|
warning_alert_stash_key => 'warning_alert', |
166
|
|
|
|
|
|
|
danger_alert_stash_key => 'danger_alert', |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
success_alert_stash_key_alias => 'status_msg', |
169
|
|
|
|
|
|
|
danger_alert_stash_key_alias => 'error_msg', |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
); |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head2 _plugin_bootstrap_alert_config |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Subref that handles default values and lets them be overriden from the MyApp |
176
|
|
|
|
|
|
|
configuration. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=cut |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
sub _plugin_bootstrap_alert_config |
181
|
|
|
|
|
|
|
{ |
182
|
0
|
|
|
0
|
|
|
my $self = shift; |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
my %config = ( |
185
|
|
|
|
|
|
|
session_key => 'bootstrap_alerts', |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
alert_param => 'mid', |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
alert_types => [ qw( success info warning danger ) ], |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
success_alert_stash_key => 'success_alert', |
192
|
|
|
|
|
|
|
info_alert_stash_key => 'info_alert', |
193
|
|
|
|
|
|
|
warning_alert_stash_key => 'warning_alert', |
194
|
|
|
|
|
|
|
danger_alert_stash_key => 'danger_alert', |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
success_alert_stash_key_alias => 'status_msg', |
197
|
|
|
|
|
|
|
danger_alert_stash_key_alias => 'error_msg', |
198
|
|
|
|
|
|
|
|
199
|
0
|
0
|
|
|
|
|
%{ $self->config->{ "Plugin::BootstrapAlert" } || {} } |
|
0
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
); |
201
|
|
|
|
|
|
|
|
202
|
0
|
|
|
|
|
|
return \%config; |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head1 INTERNALS |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
Note: You normally shouldn't need any of the information in this section |
211
|
|
|
|
|
|
|
to use L. |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=head2 _set_bootstrap_alert |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
This is called by all of the public methods, passing the type of alert, and the alert message. |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=cut |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
sub _set_bootstrap_alert |
220
|
|
|
|
|
|
|
{ |
221
|
0
|
|
|
0
|
|
|
my $self = shift; |
222
|
|
|
|
|
|
|
|
223
|
0
|
|
|
|
|
|
my $type = shift; |
224
|
|
|
|
|
|
|
|
225
|
0
|
|
|
|
|
|
my $msg = shift; |
226
|
|
|
|
|
|
|
|
227
|
0
|
|
|
|
|
|
my $config = $self->_plugin_bootstrap_alert_config; |
228
|
|
|
|
|
|
|
|
229
|
0
|
|
|
|
|
|
my $param = int( rand( 90_000_000 ) ) + 10_000_000; |
230
|
|
|
|
|
|
|
|
231
|
0
|
|
|
|
|
|
$self->session->{ $config->{ session_key } }->{ $type }->{ $param } = $msg; |
232
|
|
|
|
|
|
|
|
233
|
0
|
|
|
|
|
|
return $param; |
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=head2 _get_bootstrap_alert_by_type |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
Fetch the requested message type from the user's session |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=cut |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
sub _get_bootstrap_alert |
243
|
|
|
|
|
|
|
{ |
244
|
0
|
|
|
0
|
|
|
my $self = shift; |
245
|
|
|
|
|
|
|
|
246
|
0
|
|
|
|
|
|
my $type = shift; |
247
|
|
|
|
|
|
|
|
248
|
0
|
|
|
|
|
|
my $param = shift; |
249
|
|
|
|
|
|
|
|
250
|
0
|
|
|
|
|
|
my $config = $self->_plugin_bootstrap_alert_config; |
251
|
|
|
|
|
|
|
|
252
|
0
|
|
0
|
|
|
|
return delete( $self->session->{ $config->{ session_key } }->{ $type }->{ $param } ) || ''; |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=head1 AUTHOR |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
Rob Brown, C<< >> |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=head1 BUGS |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
263
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you will |
264
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
=head1 SUPPORT |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
perldoc Catalyst::Plugin::BootstrapAlert |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
You can also look for information at: |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=over 4 |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
L |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
L |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=item * CPAN Ratings |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
L |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
=item * Search CPAN |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
L |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
=back |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
Copyright 2017 Rob Brown. |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
300
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
301
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
=cut |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
1; |
308
|
|
|
|
|
|
|
|