|
NAMEDancer::Plugin::FlashMessage - Dancer plugin to display temporary messages, so called "flash messages".VERSIONversion 0.314DESCRIPTIONThis plugin helps you display temporary messages, so called "flash messages". It provides a "flash()" method to define the message. The plugin then takes care of attaching the content to the session, propagating it to the templating system, and then removing it from the session.However, it's up to you to have a place in your views or layout where the message will be displayed. But that's not too hard (see SYNOPSYS). Basically, the plugin gives you access to the 'flash' hash in your views. It can be used to display flash messages. By default, the plugin works using a decent configuration. However, you can change the behaviour of the plugin. See CONFIGURATION NAMEDancer::Plugin::FlashMessage - A plugin to display "flash messages" : short temporary messagesSYNOPSYSExample with Template ToolkitIn your configuration, make sure you have session configured. Of course you can use any session engine : session: "simple" In your index.tt view or in your layout : <% IF flash.error %> <div class=error> <% flash.error %> </div> <% END %> In your css : .error { background: #CEE5F5; padding: 0.5em; border: 1px solid #AACBE2; } In your Dancer App : package MyWebService; use Dancer; use Dancer::Plugin::FlashMessage; get '/hello' => sub { flash error => 'Error message'; template 'index'; }; METHODSflash# sets the flash message for the warning key flash warning => 'some warning message'; # retrieves and removes the flash message for the warning key my $warning_message = flash 'warning'; This method can take 1 or 2 parameters. When called with two parameters, it sets the flash message for the given key. When called with one parameter, it returns the value of the flash message of the given key. The message is deleted from the flash hash in the session. In both cases, "flash" always returns the value; IN YOUR TEMPLATEAfter having set a flash message using "flash" in your Dancer route, you can access the flash message from within your template. The plugin provides you with the "flash" hashref, that you can access in your template, for example like this :<div class=error> <% flash.error %> </div> When you use it in your template, the flash message is deleted. So next time, "flash.error" will not exist. CONFIGURATIONWith no configuration whatsoever, the plugin will work fine, thus contributing to the keep it simple motto of Dancer.configuration default valuesThese are the default values. See below for a description of the keysplugins: FlashMessage: token_name: flash session_hash_key: _flash configuration description
COPYRIGHTThis software is copyright (c) 2011 by Damien "dams" Krotkine <dams@cpan.org>.LICENCEThis is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.AUTHORSThis module has been written by Damien "dams" Krotkine <dams@cpan.org>.SEE ALSODancerAUTHORDamien "dams" KrotkineCOPYRIGHT AND LICENSEThis software is copyright (c) 2011 by Damien "dams" Krotkine.This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Visit the GSP FreeBSD Man Page Interface. |