[dancer-users] Managing session in before hook

Cymon cymon.ML at gmail.com
Wed Jun 19 00:30:08 BST 2013


Il giorno Tue, 18 Jun 2013 19:15:37 -0400
David Golden <xdg at xdg.me> ha scritto:

> On Tue, Jun 18, 2013 at 6:12 PM, Cymon <cymon.ML at gmail.com> wrote:
> > what is the right way to manage session in a before hook?
> 
> You need to give us more details and sample code.  Where is your
> before hook?  In your application?  Or in a plugin?  What are you
> doing in your dispatcher?
> 
> FWIW, sessions aren't flushed (e.g. to disk) until an after hook, so
> when you say "nothing is written", when are you checking?
> 
> David
> 
> --
> David Golden <xdg at xdg.me>
> Take back your inbox! → http://www.bunchmail.com/
> Twitter/IRC: @xdg
> _______________________________________________
> dancer-users mailing list
> dancer-users at dancer.pm
> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users

I give you a little not working example.
In the main package of the Dancer2 project I have:

package project;

use Dancer2 ':syntax';
use Dancer2::Template::TemplateToolkit;

hook before => sub {
    my $context = shift;
    my $newpath = '/there';	
    //this or any other of the ones I said
    $context->app->session->{'foo'} = 'bar';

    //I tried also to turn off forwording with no effect
    $context->response( forward($newpath ));
    $context->response->halt;
};

then in the dispatcher:

get '/there' => sub { 
    print session('foo'); //nothing in it
    template 'index';
};

I checked the YAML file using Session::YAML after navigation. They're
all empty.






-- 
Cymon
Coniglio domina,
http://www.therabbit.it


More information about the dancer-users mailing list