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

Dale Gallagher dale.gallagher at gmail.com
Tue Apr 9 11:36:13 BST 2013


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20130409/6d1d89ed/attachment.htm>


More information about the dancer-users mailing list