[dancer-users] Managing session in before hook
David Golden
xdg at xdg.me
Wed Jun 19 01:06:47 BST 2013
I'm not sure what exactly is the problem, but I'm perplexed why you're
importing only ":syntax" -- that means your code isn't setting up a
dancer app properly. And you're calling forward from a hook and I
think that might only valid from a request handler.
Here's a simple example that works:
https://gist.github.com/dagolden/5810631
If you run that and go to the localhost URL, you should see "bar" (as
set in the session).
I hope that helps you get on the right track.
David
On Tue, Jun 18, 2013 at 7:30 PM, Cymon <cymon.ML at gmail.com> wrote:
> 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
> _______________________________________________
> dancer-users mailing list
> dancer-users at dancer.pm
> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
--
David Golden <xdg at xdg.me>
Take back your inbox! → http://www.bunchmail.com/
Twitter/IRC: @xdg
More information about the dancer-users
mailing list