- CONFIGURATION AND ENVIRONMENT
- BUGS AND LIMITATIONS
- SEE ALSO
- LICENCE AND COPYRIGHT
- DISCLAIMER OF WARRANTY
Dancer2::Plugin::Growler - Growl multiple messages of varying types to the user on their next hit.
This document describes Dancer2::Plugin::Growler version 0.03
use Dancer2::Plugin::Growler; … my $error = locale->maketext('Invalid login credentials.'); # locale() is from L<Dancer2::Plugin::Locale> growl_error($error); redirect '/login'; … my $msg = locale->maketext('Successfully created post the post “[_1]”.', $html_safe_title); # locale() is from L<Dancer2::Plugin::Locale> growl_success($msg); redirect "/post/$new_id";
Then in the view’s layout (this example implies a bootstrap3/jquery environment w/ the bootstrapGrowl jquery plugin):
This allows you to specify one or more one-time messages (of varying types) to growl on the user’s next hit (or this hit if you render a view that implements it) with out needing to pass around parameters.
It is also a nice approach because it is refresh safe. For example, in the SYNOPSIS example with the blog post, say we rendered the message at the end of the request instead: refreshing the page could cause us to post the blog article again.
It is similar to the “flash” example in the Dancer2 documentation but without the multi-user race condition and limitation of one message.
It is also AJAX-safe (don’t call growls() in your AJAX templates and you won’t miss any message) yet still AJAX-able (call growls() in your AJAX templates in order to include them in your response).
The first argument is the message to growl. The second, optional argument is hashref of arguments.
The keys it can specify are:
The type of message. The values, if given, can be: 'info', 'success', 'warning', or 'danger' (That last one is from bootstrap convention).
The number of milliseconds you intend the growl to display before fading out.
Boolean of if the growl should be dismissible via a close icon.
If the delay is turned off this is forced to true so that we don’t end up with a permanent growl on the screen.
Same as growl() but forces a type of 'info'.
Same as growl() but forces a type of 'success'.
Same as growl() but forces a type of 'warning'.
Same as growl() but forces a type of 'danger' (That is from bootstrap convention).
For the consumer to use in its templates (though it is availaable in perl also).
It returns the list of growls (if any) and clears the list.
Each growl consists of two keys:
The message to display.
The hashref of options for the view that can include 'delay' and 'allow_dismiss' noted above.
See the SYNOPSIS for an example.
Throws no warnings or errors of its own.
Dancer2::Plugin::Growler requires no configuration files or environment variables.
No bugs have been reported.
Please report any bugs or feature requests to
email@example.com, or through the web interface at http://rt.cpan.org.
Dancer2::Plugin::Deferred does a similar thing but, for my growling needs, it turned out to be overly complex and not flexible enough.
Copyright (c) 2015, Daniel Muey
<http://drmuey.com/cpan_contact.pl>. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.