[Dancer-users] trouble with sessions

Mr. Puneet Kishor punk.kish at gmail.com
Fri Mar 25 13:22:35 CET 2011


On Mar 25, 2011, at 6:27 AM, David Precious wrote:

> On Friday 25 March 2011 03:51:49 Mr. Puneet Kishor wrote:
>> Seems like $self->id is not generating a session id.
> 
> 
> Ah, looking at Dancer::Session::Abstract, the ID is set when the init method 
> gets called; you've overriden the init method in Dancer::Session::SQLite, so 
> the init() method in D::S::Abstract won't get called.


Well, this wasn't the problem all this time, literally months (I started my github repo for this module in Aug, 2010, and the module has worked just fine until two days ago). How come it started to be a problem a couple of days back?

If you note from the repo at [https://github.com/punkish/Dancer--Session--SQLite], the session is generated not via init, but via create. See below

sub create {
    my ($class) = @_;

    my $self = Dancer::Session::Storable->new;
    $self->flush;
    return $self;
}


init simply sets up the db connection (or check that the session dir exists, in the case of file based session backends).

Nevertheless...

> 
> I think you need to add something like the following to your init() :
> 
> $self->SUPER::init(@_);

I added the above to create(), not to init(), so create() now looks like so

sub create {
    my ($class) = @_;

    my $self = Dancer::Session::SQLite->new;
    **** new line **** $self->SUPER::init(@_);
    $self->flush;
    return $self;
}


Yes, now the session id is generated, and things work as before. But, is this the correct fix? I am looking at your DSStorable for the pattern, and you have no such session SUPER::init() method in there.


> 
> That will call init() from D::S::Abstract, which looks like:
> 
> 
> sub init {
>    my ($self) = @_;
>    $self->id(build_id());
> }
> 
> 
> Cheers
> 
> Dave P
> 
> -- 
> David Precious <davidp at preshweb.co.uk> (bigpresh)
> http://www.preshweb.co.uk/
> 
>  "Programming is like sex. One mistake and you have to support 
>  it for the rest of your life". (Michael Sinz)



More information about the Dancer-users mailing list