[Dancer-users] Routes with captures

Marc Chantreux khatar at phear.org
Sun May 30 18:13:36 CEST 2010


Hello all,

Today, I cloned the dancer repo to add the ability to use Regexps as
route (a one line patch).

so, i can now write

any [qw| get post |]
, qr{
    ^
    / ( user | post ) 
    / ( C|R|U|D | create | read | update | delete )
    / ( \d+ )
    /? $ 
}x
, sub {
    my $url;
    @$url{qw/ class action id /} = splat;
    ...;
}; 

I would like to go a bit further adding the support of perl 5.10
named captures. So the same code would become: 

any [qw| get post |]
, qr{
    ^
    / (?<class> user | post ) 
    / (?<action> C|R|U|D | create | read | update | delete )
    / (?<id> \d+)
    /? $ 
}x
, sub {
    my $url = splat->{capture};
    # so $$url{action} ~~ [qw/ C R U D create read update delete /]
    ...;
};

But i can ignore something about the current form

any [qw| get post |], '/:class/:action/:id' => sub {
    ...;
};

I appreciate to have your feelings abont that before writing some code
that doesn't fit the spirit of the framework.

Regards
marc 


More information about the Dancer-users mailing list