NAME
Catalyst::Plugin::BootstrapAlert - Replacement for Catalyst::Plugin::StatusMessage inline with Bootstrap alert names (success, info, warning, and danger).
VERSION
Version 0.20
SYNOPSIS
Replacement for Catalyst::Plugin::StatusMessage using Bootstrap alert names (success, info, warning, and danger), whilst also keeping status_msg
and error_msg
as aliases.
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_msg("It worked!") );
Or, to save an danger message:
$c->response->redirect( "/?mid=" . $c->set_danger_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 $c-
load_status_msgs> if using Catalyst::Plugin::StatusMessage
.
And, to display the output (here using Template Toolkit):
...
<span class="message">[% success_alert %]</span>
<span class="error">[% danger_alert %]</span>
...
METHODS
load_bootstrap_alerts
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_msg
", "info_msg
", "warning_msg
", and "danger_msg
", you can automatically and safely send status messages to any related controller action.
set_success_alert
Sets the success alert text.
set_info_alert
Sets the info alert text.
set_warning_alert
Sets the warning alert text.
set_danger_alert
Sets the danger alert text.
set_status_msg
Sets the info alert text - this is an alias for when you're switching out Catalyst::Plugin::StatusMessage.
set_error_msg
Sets the danger alert text - this is an alias for when you're switching out Catalyst::Plugin::StatusMessage.
CONFIGURABLE OPTIONS
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',
}
);
_plugin_bootstrap_alert_config
Subref that handles default values and lets them be overriden from the MyApp configuration.
INTERNALS
Note: You normally shouldn't need any of the information in this section to use Catalyst::Plugin::BootstrapAlert.
_set_bootstrap_alert
This is called by all of the public methods, passing the type of alert, and the alert message.
_get_bootstrap_alert_by_type
Fetch the requested message type from the user's session
AUTHOR
Rob Brown, <rob at lavoco.com>
BUGS
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.
SUPPORT
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
CPAN Ratings
http://cpanratings.perl.org/d/Catalyst-Plugin-BootstrapAlert
Search CPAN
LICENSE AND COPYRIGHT
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.