[dancer-users] Dancer2: session->destroy fails

Dale Gallagher dale.gallagher at gmail.com
Wed Apr 10 09:31:02 BST 2013


Thanks David, that resolved it.


On 9 April 2013 12:46, David Golden <xdg at xdg.me> wrote:

> The session paradigm changed in D2.  Session objects are now just data
> objects, so you have to destroy them via the context object, which
> dispatches to the configured session engine and does some other
> necessary bookkeeping:
>
>     context->destroy_session
>
> -- David
>
> On Tue, Apr 9, 2013 at 6:36 AM, Dale Gallagher <dale.gallagher at gmail.com>
> wrote:
> > Hi
> >
> > Calling session->destroy fails with the following.
> >
> >
> > Can't locate object method "destroy" via package
> "Dancer2::Core::Session" at
> > /srv/web/app/lib/app.pm line 36.
> >
> >
> > config.yml:
> >
> > session: Simple
> >
> > /srv/web/app/lib/app.pm:
> >
> > package app;
> > use Dancer2 ':syntax';
> > use Dancer2::Plugin::Ajax;
> > use Authen::Simple::Passwd;
> >
> >
> > ...
> > ..
> >
> > get '/logout' => sub {
> >
> >   session->destroy;
> >
> >   redirect '/login';
> >
> > }
> >
> > I even tried:
> >
> > my $id = session->id;
> >
> > session->delete($id);
> >
> > but, even though it doesn't throw an error, it doesn't delete the session
> > and other routes are served.
> >
> > So far, at the top of app.pm, I have:
> >
> >
> > hook before => sub {
> >   if (request->path_info !~ m{^/login}) {
> >     if (session('user') && session('time')) {
> >       my $time_now = time;
> >       if ($time_now - session('time') < config->{'session_expire'}) {
> >
> >         session 'time' => time;
> >       }
> >       else {
> >         return redirect '/logout?msg=session_expired&path=' .
> > request->path_info;
> >       }
> >     }
> >     else {
> >       return redirect '/login';
> >
> >     }
> >   }
> > };
> >
> >
> > I'm stumped, as, apart from the above snippet, and the Dancer2 use lines,
> > the app works under Dancer1.
> >
> > Any pointers would be appreciated.
> >
> > Thanks
> >
> > Dale
> >
> >
> > _______________________________________________
> > 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
> _______________________________________________
> dancer-users mailing list
> dancer-users at dancer.pm
> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20130410/1b6ac246/attachment.htm>


More information about the dancer-users mailing list