[Dancer-users] idiom for programming the Perl OO way with Dancer
P Kishor
punk.kish at gmail.com
Tue Aug 3 16:39:26 CEST 2010
The following would hopefully be a welcome change from my usual "I
can't deploy" emails ;-).
I am looking for the right idiom(s) for programming correctly with
Dancer. Right now, my dance.pm looks a mess
package dance;
use Dancer ':syntax';
# bunch of modules #####################
use Tie::File;
use Tie::File::AsHash;
use URI::Escape;
use lib '/Users/punkish/Library/Perl';
use Markdown 'markdown';
my $markdown_opts = {url_prefix => '/', url_pattern => '-'};
# end bunch of modules #################
our $VERSION = '0.1';
get '/*?' => sub {
my ($p) = splat;
my $page_name = $p ? $p : config->{default_page};
if ( $page_name =~ /slideshow/ ) {
template 'album.tt', {..};
}
elsif ($page_name =~ /maps/ {
template 'map.tt', {..};
}
elsif ($page_name =~ /something_else/ {
template 'something_else.tt', {..};
}
else {
template 'default.tt', {..};
}
};
sub slideshow {
..
}
sub maps {
..
}
sub something_else {
..
}
The above is just the beginning. All those subs and methods not only
make for a very long dance.pm, they also clash syntactically with
Dancer's magic "get '/' => sub {}" idiom.
Now, in the world of CGI::Application, I would actually sub-class
CGI::Application, add my custom methods and junk to it, and then
sub-class that custom instance into my application instance which
would then be clean. Yes, I know, I am sweeping the crap under the
carpet, but at least the carpet it clean.
Is there something like that I can do with Dancer? Can I create a
sub-class of Dancer, add my custom stuff to it, and then create
application instances with it and program with it the Perl OO way?
Has someone written a tute on that? :-)
--
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