[Dancer-users] route classes

damien krotkine dkrotkine at gmail.com
Mon Apr 23 16:56:34 CEST 2012


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 :)

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