The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Catalyst::Plugin::BootstrapAlert - Replacement for Catalyst::Plugin::StatusMessage inline with Bootstrap alert names (success, info, warning, and danger).

VERSION

Version 0.50

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.

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:

    [% 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.

And, to display the output (here using Template Toolkit):

    ...
    <span class="message">[% success_alert %]</span>
    <span class="error">[% error_msg %]</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_alert", "info_alert", "warning_alert", and "danger_alert", 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 success 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

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:

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.