nathaniels has asked for the wisdom of the Perl Monks concerning the following question:

Hello All,

I seem to be unable to create/set cookies using Dancer. I'm sure I'm missing something small. Here's the code:

any ['get', 'post'] => '/viewscript' => sub { set_cookie name => 'return_page', value => '/viewscript'; if ( request->is_get() ) { forward "/selectscript"; } } any ['get', 'post'] => '/selectscript' => sub { my $return_page = cookies->{ return_page }; print $return_page; }

Thanks for the help!

Replies are listed 'Best First'.
Re: Dancer Cookies
by Anonymous Monk on Nov 13, 2013 at 03:36 UTC
    What output do you get with  lwp-request -UusSeEd  http://localhost...

      GET http://localhost:3000/selectscript
      User-Agent: lwp-request/6.03 libwww-perl/6.05

      200 OK
      Server: Perl Dancer 1.3118
      Content-Length: 1537
      Content-Type: text/html; charset=utf-8
      Client-Date: Wed, 13 Nov 2013 03:46:08 GMT
      Client-Peer: 127.0.0.1:3000
      Client-Response-Num: 1
      Link: <http://localhost:3000/css/style.css>; rel="stylesheet"
      Title: scriptanalysiswebapp
      X-Powered-By: Perl Dancer 1.3118

        funny, selectscript doesn't try to set any cookies, only viewscript sets cookies, maybe you want to request viewscript first and show that?