[Dancer-users] Flash Message

Puneet Kishor punk.kish at gmail.com
Tue Jan 11 19:44:33 CET 2011


On Tuesday, January 11, 2011 at 11:48 AM, damien krotkine wrote:

> I've re-implemented it to be more Rails-like, as sukria said.
> 
> https://github.com/dams/Dancer-Plugin-FlashMessage
> 
> and on CPAN, pending mirrors refresh.
> 
> The funny part of the story ? the effective code is only 30 lines
> long. Talking about Perl and Dancer expressiveness...
> 
> 




Great job, and thanks! But, I don't really understand the point of this flash message (for the longest time I thought it was something to do with Adobe Flash). Is there a demo of it in action that I can see? I am trying to visualize which nail I can bang in with this hammer. Where would I use this, and how?


Thanks.

> 
> 
> dams.
> 
> On 11 January 2011 14:40, Alexis Sukrieh <sukria at sukria.net> wrote:
> 
> > Hi list!
> > 
> > Le 11/01/2011 14:29, damien krotkine a écrit :
> > 
> > > 
> > > Hi,
> > > 
> > > following previous thread, I've done a first implementation of
> > > Dancer::Plugin::FlashMessage :
> > > 
> > > https://github.com/dams/Dancer-Plugin-FlashMessage
> > > 
> > > 
> > 
> > Great! Thanks a lot for your time dams, the myth is still alived! (Dancer's
> > community)++
> > 
> > 
> > 
> > 
> > > Some parts need to be improved, for instance :
> > > 
> > > - it supports only one flash message
> > > - the keywords are not short enough.
> > > 
> > > So I think I'll change the implementation so that the template token is
> > > simply called 'flash', and it'll be a hash, like in Rails. I'll also
> > > change the registered method so that it's just flash() instead of
> > > get_flash()
> > > 
> > > 
> > 
> > I agree. I'd like to behave just like Rails' flash feature. The idea is
> > pretty straight forward:
> > 
> > "flash" is an accessor to a particular session hash table whose values can
> > only be accessed once. Nothing more complicated than that.
> > 
> > So to conclude, IMO, flash should be a wrapper like the following:
> > 
> > sub flash {
> > my ($key, $value) = @_;
> > my $flash = session('_flash');
> > 
> > # write
> > if (@_ == 2) {
> >  $flash->{$key} = $value;
> >  session('_flash' => $flash);
> > }
> > 
> > # read (+ delete)
> > else {
> > my $value = $flash->{$key};
> > delete $flash->{$key} if defined $value;
> > session('_flash' => $flash);
> > }
> > 
> > return $value;
> > }
> > 
> > This is it, I think. This allows for the following code in a Dancer app:
> > 
> > 
> >  get '/' => sub {
> >  flash welcome => "This is a welcome message, only shown once";
> >  }
> > 
> > Then, as soon as the key 'welcome' is accesed via flash('welcome'), the
> > entry will be purged.
> > 
> > This will be very helpful for authentication stuff in before filters, error
> > messages, notifications, ....
> > 
> > 
> > Kudos to dams!
> > 
> > (BTW I haven't read the code yet)
> > 
> > --
> > Alexis Sukrieh
> > _______________________________________________
> > Dancer-users mailing list
> > Dancer-users at perldancer.org
> > http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
> > 
> > 
> _______________________________________________
> Dancer-users mailing list
> Dancer-users at perldancer.org
> http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
> 
> 
> 




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.backup-manager.org/pipermail/dancer-users/attachments/20110111/2903105c/attachment-0001.htm>


More information about the Dancer-users mailing list