[Dancer-users] request for feature

Puneet Kishor punk.kish at gmail.com
Mon Jan 17 23:25:47 CET 2011


On Monday, January 17, 2011 at 5:13 PM, Flavio Poletti wrote:

> I think that Puneet is suggesting to have a syntax for non-mandatory parts in the route specifier, i.e. the foo_id might be there, as in:
> 
> 
> /foo/1/bar/30
> 
> 
> or not, as in
> 
> 
> /foo/bar/30
> 
> 
> in which case a default value for foo_id can be set inside the route handler. Trying to guess a possible regex for it (don't know if "\w" is correct here):
> 
> 
>  /foo(?:/(?<foo_id>:\w+))?/bar(?:/(?<bar_id>:\w+))
> 
> 
> i.e. each named capture "name" for a parameter is expanded to "(?:/(?<name>:\w+))?" (or whatever is used instead of "\w" today).
> 
> 
> 




Yeah, kinda. Actually, I gave a wrong-ish example because of more than one params, which makes the capture more difficult requiring the hairy regexp you provided above. But yes, you got the spirit of the question. Consider the more common


get '/books'
get '/books/:book_id'


I need two routes as above. Would be nice to just have one like below that does the job of both


get '/books/:book_id?'


The above is how it is implemented in CGI::Application, hence my experience with such a capability.


Thanks,





> 
> 
> 
> Cheers,
> 
> 
>  Flavio.
> 
> On Mon, Jan 17, 2011 at 11:01 PM, sawyer x <xsawyerx at gmail.com> wrote:
> 
> > I don't follow
> > 
> > 
> > On Mon, Jan 17, 2011 at 9:03 PM, Puneet Kishor <punk.kish at gmail.com> wrote:
> > 
> > >  unless default params already exist, the following would make life a lot easier
> > > 
> > >  get '/foo/:foo_id?/bar/:bar_id?' => sub {
> > > my $foo_id = params->{'foo_id'} || <default foo value>;
> > > my $bar_id = params->{'bar_id'} || <default bar value>;
> > >  };
> > > 
> > >  Many thanks,
> > > 
> > > 
> > >  -- 
> > >  Puneet Kishor
> > >  _______________________________________________
> > >  Dancer-users mailing list
> > > Dancer-users at perldancer.org
> > > http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
> > > 
> > > 
> > 
> > 
> > 
> > 
> > 
> > 
> > _______________________________________________
> >  Dancer-users mailing list
> > Dancer-users at perldancer.org
> > http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
> > 
> > 
> > 
> 
> 
> 
> 
> _______________________________________________
> Dancer-users mailing list
> Dancer-users at perldancer.org
> http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
> 
> 
> 




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.backup-manager.org/pipermail/dancer-users/attachments/20110117/58e28bb5/attachment.htm>


More information about the Dancer-users mailing list