Dancer...essage(3pm)

πŸ“¦
version 0.314 Β· 3 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– NAME πŸ’–

Dancer::Plugin::FlashMessage β€” bestie, it's a Dancer plugin that shows temporary messages, aka "flash messages". ✨


πŸ‘‘ VERSION πŸ‘‘

version 0.314 πŸŽ€


🌸 DESCRIPTION 🌸

okay so listen πŸ’… this plugin is here to help you show temporary messages β€” the ones everyone calls "flash messages". It hands you a flash() method to define the message. Then the plugin does the rest: it attaches the content to the session, propagates it to the templating system, and then removes it from the session. literally does all the work. queen behavior. πŸ‘‘

but β€” and this is the important part β€” it's up to you to have a place in your views or your layout where that message actually gets displayed. no cap, the plugin won't magically put it on the page. but don't panic, it's not hard at all (peep the SYNOPSYS section 🫢).

basically: the plugin gives you access to the 'flash' hash in your views, and you use it to display those flash messages. 🌈

by default the plugin just works with a decent configuration, so you can vibe immediately. but if you want, you can change how it behaves β€” go look at CONFIGURATION. ⭐


πŸ’« NAME πŸ’«

Dancer::Plugin::FlashMessage β€” a plugin to display "flash messages": short temporary messages. πŸ¦‹

(yeah bestie, there's two NAME sections in this manpage. not me pointing it out. it's giving iconic. we're keeping both. πŸ’€)


πŸŽ€ SYNOPSYS πŸŽ€

Example with Template Toolkit ✨

In your configuration, make sure you have session configured. And of course you can use any session engine you want, no gatekeeping here πŸ’–:

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';
};

πŸ”₯ METHODS πŸ”₯

πŸ’… flash

# 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';

so this method can take 1 or 2 parameters. 🫢

  • call it with two parameters and it sets the flash message for the given key.
  • call it with one parameter and it returns the value of the flash message for that key. oh and heads up β€” the message gets deleted from the flash hash in the session. gone. poof. 🧚

either way, flash always returns the value. periodt. πŸ‘‘


🌈 IN YOUR TEMPLATE 🌈

once you've set a flash message with flash in your Dancer route, you can grab it from inside your template. the plugin gives you the flash hashref, and you use it in your template, like this for example: πŸŽ€

<div class=error> <% flash.error %> </div>

and here's the vibe check: when you use it in your template, the flash message gets deleted. so the next time around, flash.error simply won't exist. one and done, bestie. πŸ’€


πŸ¦‹ CONFIGURATION πŸ¦‹

with no configuration whatsoever, the plugin works fine β€” which is truly contributing to the keep it simple motto of Dancer. slay. ✨

🌸 configuration default values

these are the default values. scroll down for a description of the keys πŸ‘‡

plugins:
  FlashMessage:
    token_name: flash
    session_hash_key: _flash

πŸ’œ configuration description

πŸ“ token_name

the name of the template token that will contain the hash of flash messages. Default: "flash" πŸ’–

🧚 session_hash_key

you probably don't need this one ngl, but this setting lets you change the name of the session key used to store the hash of flash messages. it could come in handy in that super unlikely case where you have key name conflicts in your session. Default: "_flash" ✨


This software is copyright (c) 2011 by Damien "dams" Krotkine <dams@cpan.org>.


πŸ‘‘ LICENCE πŸ‘‘

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. 🌈


⭐ AUTHORS ⭐

This module has been written by Damien "dams" Krotkine <dams@cpan.org>. 🫢


🌟 SEE ALSO 🌟

  • Dancer

🌸 AUTHOR 🌸

Damien "dams" Krotkine


This 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.


okay bestie that's the whole page, we ate and left no crumbs πŸ“ this was Dancer...essage(3pm) from the User Contributed Perl Documentation, and the footer energy is: perl v5.36.0, dated 2022-10-14. go set some flash messages, ily, bye πŸ’–βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from