File Coverage

blib/lib/Catalyst/Plugin/BootstrapAlert.pm
Criterion Covered Total %
statement 8 45 17.7
branch 0 10 0.0
condition 0 2 0.0
subroutine 3 13 23.0
pod 7 7 100.0
total 18 77 23.3


line stmt bran cond sub pod time code
1             package Catalyst::Plugin::BootstrapAlert;
2              
3 1     1   13902 use 5.006;
  1         3  
4              
5 1     1   6 use strict;
  1         2  
  1         19  
6 1     1   5 use warnings;
  1         8  
  1         467  
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.50
15              
16             =cut
17              
18             our $VERSION = '0.50';
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             Storing an array-ref of msgs, or even an array-ref of hash-refs is fine, in TT you'd want to use the C VMethod:
28              
29             [% IF danger_alert.list.size %]
30            
31             [% FOREACH each_danger_alert IN danger_alert.list %]
32            

[% each_danger_alert %]

33             [% END %]
34            
35             [% END %]
36              
37             Calling C on an actual list just returns the list, so essentially a no-op.
38              
39             See http://www.template-toolkit.org/docs/manual/VMethods.html#section_list
40              
41             In MyApp.pm:
42              
43             use Catalyst qr/
44             BootstrapAlert
45             /;
46              
47             In controller where you want to save a message for display on the next page:
48              
49             $c->response->redirect( "/?mid=" . $c->set_success_alert("It worked!") );
50              
51             Or, to save an danger message:
52              
53             $c->response->redirect( "/?mid=" . $c->set_error_msg("Error deleting widget") );
54              
55             Then, in the controller action that corresponds to the redirect above:
56              
57             sub list :Path {
58             my ($self, $c) = @_;
59             ...
60             $c->load_bootstrap_alerts;
61             ...
62             }
63              
64             This would mean simply changing C if using C.
65              
66             And, to display the output (here using L