Catalyst::Plugin::BootstrapAlert - Replacement for Catalyst::Plugin::StatusMessage inline with Bootstrap alert names (success, info, warning, and danger).
Version 0.50
Replacement for Catalyst::Plugin::StatusMessage using Bootstrap alert names (success, info, warning, and danger), whilst also keeping status_msg and error_msg as aliases.
status_msg
error_msg
Storing an array-ref of msgs, or even an array-ref of hash-refs is fine, in TT you'd want to use the list VMethod:
list
[% IF danger_alert.list.size %] <div class="alert alert-danger" role="alert"> [% FOREACH each_danger_alert IN danger_alert.list %] <p>[% each_danger_alert %]</p> [% END %] </div> [% END %]
Calling list on an actual list just returns the list, so essentially a no-op.
See http://www.template-toolkit.org/docs/manual/VMethods.html#section_list
In MyApp.pm:
use Catalyst qr/ BootstrapAlert /;
In controller where you want to save a message for display on the next page:
$c->response->redirect( "/?mid=" . $c->set_success_alert("It worked!") );
Or, to save an danger message:
$c->response->redirect( "/?mid=" . $c->set_error_msg("Error deleting widget") );
Then, in the controller action that corresponds to the redirect above:
sub list :Path { my ($self, $c) = @_; ... $c->load_bootstrap_alerts; ... }
This would mean simply changing load_status_msgs if using Catalyst::Plugin::StatusMessage.
load_status_msgs
Catalyst::Plugin::StatusMessage
And, to display the output (here using Template Toolkit):
... <span class="message">[% success_alert %]</span> <span class="error">[% error_msg %]</span> ...
Load all alerts that match the token parameter on the URL (e.g., http://example.com/dashboard?mid=1234567890) into the stash for display by the viewer.
In general, you will want to include this in an auto or "base" (if using Chained dispatch) controller action. Then, if you have a "template wrapper page" that displays "success_alert", "info_alert", "warning_alert", and "danger_alert", you can automatically and safely send status messages to any related controller action.
auto
success_alert
info_alert
warning_alert
danger_alert
Sets the success alert text.
Sets the info alert text.
Sets the warning alert text.
Sets the danger alert text.
Sets the success alert text - this is an alias for when you're switching out Catalyst::Plugin::StatusMessage.
Sets the danger alert text - this is an alias for when you're switching out Catalyst::Plugin::StatusMessage.
Here is a quick example showing how Catalyst::Plugin::BootstrapAlert can be configured:
# Configure Catalyst::Plugin::BootstrapAlert __PACKAGE__->config( 'Plugin::BootstrapAlert' => { session_key => 'my_status_msg', alert_param => 'my_mid', alert_types => [ qw( success info warning danger ) ], success_alert_stash_key => 'success_alert', info_alert_stash_key => 'info_alert', warning_alert_stash_key => 'warning_alert', danger_alert_stash_key => 'danger_alert', success_alert_stash_key_alias => 'status_msg', danger_alert_stash_key_alias => 'error_msg', } );
Subref that handles default values and lets them be overriden from the MyApp configuration.
Note: You normally shouldn't need any of the information in this section to use Catalyst::Plugin::BootstrapAlert.
This is called by all of the public methods, passing the type of alert, and the alert message.
Fetch the requested message type from the user's session
Rob Brown, <rob at lavoco.com>
<rob at lavoco.com>
Please report any bugs or feature requests to bug-catalyst-plugin-bootstrapalert at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-Plugin-BootstrapAlert. I will be notified, and then you will automatically be notified of progress on your bug as I make changes.
bug-catalyst-plugin-bootstrapalert at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Catalyst::Plugin::BootstrapAlert
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-Plugin-BootstrapAlert
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Catalyst-Plugin-BootstrapAlert
CPAN Ratings
http://cpanratings.perl.org/d/Catalyst-Plugin-BootstrapAlert
Search CPAN
http://search.cpan.org/dist/Catalyst-Plugin-BootstrapAlert/
Copyright 2017 Rob Brown.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install Catalyst::Plugin::BootstrapAlert, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Catalyst::Plugin::BootstrapAlert
CPAN shell
perl -MCPAN -e shell install Catalyst::Plugin::BootstrapAlert
For more information on module installation, please visit the detailed CPAN module installation guide.