[Dancer-users] route classes

Puneet Kishor punk.kish at gmail.com
Mon Apr 23 17:04:04 CEST 2012


On Apr 23, 2012, at 9:56 AM, damien krotkine wrote:

> I suggest you use either :
> - prefix + hooks
> - your own classes, which you use inside your routes (so the first
> line of route code would be to instanciate a controller.
> - move to a full-featured MVC framework :)  I don't think you need
> that, but you're free to do it :)


Oh no... never. Never will I move away from Dancer.

I will give hooks a stab (unintentional pun). Could you direct me to some code example for rolling my own class that would instantiate a controller inside a route?


> 
> On 23 April 2012 16:47, Puneet Kishor <punk.kish at gmail.com> wrote:
>> Is it possible to create route classes in a base module and then have all derived instance routes inherit from the parent class? Kinda like so --
>> 
>>    use Dance;
>> 
>>    get '/' => sub {
>>        my $name = param 'name';
>>        return "name is required for all GETs" unless $name;
>>    };
>> 
>> 
>>    post '/' => sub {
>>        my $id = param 'id';
>>        return "id is required for all POSTs" unless $id;
>>    };
>> 
>>    ----
>>    use MyDance;
>>    use base 'Dance';
>> 
>>    get '/' => sub {
>>        my $foo = param 'foo';
>>        .. do something with $foo and $name but only if $name is defined ..
>>    };
>> 
>> 
>> For bonus points, it would be nice to have base route classes only for routes that end with a '.:format'. For example, only for routes that request 'resource.json'
>> 
>> 
>> Is the above possible?
>> 
>> 
>> --
>> Puneet Kishor
>> _______________________________________________
>> Dancer-users mailing list
>> Dancer-users at perldancer.org
>> http://www.backup-manager.org/cgi-bin/listinfo/dancer-users



More information about the Dancer-users mailing list