[Dancer-users] applying the same setting to different routes in different packages
P Kishor
punk.kish at gmail.com
Tue Oct 5 00:04:30 CEST 2010
A stylistic question, perhaps a strategy question. This is what I do right now
- foo.pl ---
use Dancer;
..
load_app 'foo';
dance;
----
- foo.pm ---
load_app 'foo:bar', prefix => '/bar';
load_app 'foo:baz', prefix => '/baz';
get '/' => sub { template 'index', opts(); };
sub opts {
return {
various settings;
'logged_in' => session->{logged_in} ? 1 : 0;
}
}
----
- foo/foo.pm ---
get '/' => sub { template 'index', opts(); };
sub opts {
return {
various settings;
'logged_in' => session->{logged_in} ? 1 : 0;
}
}
----
- foo/bar.pm ---
get '/' => sub { template 'index', opts(); };
sub opts {
return {
various settings;
'logged_in' => session->{logged_in} ? 1 : 0;
}
}
----
While some of the "various settings" are different in the different
packages, some of them are the same. Definitely, 'logged_in' is the
same across all the packages, so I want to set it only in one place.
Since Dancer doesn't support the concept of creating a base class, and
then inheriting from it, how do I apply same settings to any route in
any package or sub-package?
--
Puneet Kishor http://www.punkish.org
Carbon Model http://carbonmodel.org
Charter Member, Open Source Geospatial Foundation http://www.osgeo.org
Science Commons Fellow, http://sciencecommons.org/about/whoweare/kishor
Nelson Institute, UW-Madison http://www.nelson.wisc.edu
-----------------------------------------------------------------------
Assertions are politics; backing up assertions with evidence is science
=======================================================================
More information about the Dancer-users
mailing list