[Dancer-users] get the right lib path

Puneet Kishor punk.kish at gmail.com
Mon Jan 17 02:45:12 CET 2011

Replying to my own email to add some additional info I just discovered. 
See below --

Puneet Kishor wrote:
> I am trying to build a little framework for myself with some custom
> functionality. Consider the following
> /Users/punkish/Sites/app/lib/mydance.pm
> ---------------------------------------
> package mydance;
> use Dancer ':syntax';
> use Dancer::Plugin::Email;
> use Crypt::GeneratePassword;
> use DBI;
> prefix '/mydance';

If I remove the above `prefix` line, the application works. However, the 
reason I have that line is because I want to accomplish the following --

I want my app to inherit from mydance. Then, assuming my app is at 
http://server/, if the user requests http://server/anything, it is 
served from the routes in app.pm, however, if 
http://server/mydance/anything is requested, then those are served from 
mydance.pm routes.

How do I accomplish the above?

> get '/' => sub { template '/index', opts(); };
> sub opts { return { app_name => config->{app_name} } }
> /Users/punkish/Sites/app/lib/app.pm
> -----------------------------------
> package app;
> use Dancer ':syntax';
> use base 'mydance';
> get '/' => sub { template 'index.tt', __PACKAGE__->SUPER::opts(); };
> -----
> If I remove the `use base 'mydance'` line and remove the call to
> `__PACKAGE__->SUPER::opts()` the above works, but of course, the app is
> not base-d on mydance. With the code as above, I get the dancer 404
> "this is the void" message.
> What am I doing wrong?
> Eventually, I would like to move mydance to some other central location
> that would be in @INC, so other applications I develop can also be
> base-d on mydance.
> Puneet.

More information about the Dancer-users mailing list