[Dancer-users] Dancer::Session::YAML initialises sessions dir for every new session

Al calyx2011 at gmail.com
Wed Apr 27 23:54:10 CEST 2011


Just a passing comment as I only use this module for testing purposes...

I have noticed that Dancer::Session::YAML tries to initialize the
sessions directory for every new session, causing the following log
messages to appear repeatedly:

[15144]  core @0.000064> session_dir : /home/al/dancertest/sessions in
/usr/local/libdata/perl5/site_perl/Dancer/Session/YAML.pm l. 34
[15144]  core @0.097106> [hit #2]session_dir :
/home/al/dancertest/sessions in
/usr/local/libdata/perl5/site_perl/Dancer/Session/YAML.pm l. 34
[15144]  core @0.086822> [hit #8]session_dir :
/home/al/dancertest/sessions in
/usr/local/libdata/perl5/site_perl/Dancer/Session/YAML.pm l. 34
[15144]  core @0.085747> [hit #14]session_dir :
/home/al/dancertest/sessions in
/usr/local/libdata/perl5/site_perl/Dancer/Session/YAML.pm l. 34
[15144]  core @0.095747> [hit #19]session_dir :
/home/al/dancertest/sessions in
/usr/local/libdata/perl5/site_perl/Dancer/Session/YAML.pm l. 34

This is inefficient and can be avoided by removing the following lines
prepended with "x", so that the initialization code is run just once
when the module is loaded by the "session" hook in Dancer::Config.

 x17 sub init {
 x18     my $self = shift;
 x19     $self->SUPER::init(@_);
 20
 21     croak "YAML is needed and is not installed"
 22       unless Dancer::ModuleLoader->load('YAML');
 23
 24     # default value for session_dir
 25     setting('session_dir' => path(setting('appdir'), 'sessions'))
 26       if not defined setting('session_dir');
 27
 28     # make sure session_dir exists
 29     my $session_dir = setting('session_dir');
 30     if (!-d $session_dir) {
 31         mkdir $session_dir
 32           or croak "session_dir $session_dir cannot be created";
 33     }
 34     Dancer::Logger::core("session_dir : $session_dir");
 x35 }


More information about the Dancer-users mailing list