[Dancer-users] Matching a route including slashes (for directory listing)

Joel Roth joelz at pobox.com
Sun Jan 30 19:08:38 CET 2011


On Sun, Jan 30, 2011 at 02:25:53PM +0200, sawyer x wrote:
> On Sun, Jan 30, 2011 at 2:21 PM, Al Newkirk & Associates <we at ana.im> wrote:
> 
> > On Sun, Jan 30, 2011 at 5:05 AM, sawyer x <xsawyerx at gmail.com> wrote:
> >
> >> On Sun, Jan 30, 2011 at 11:46 AM, Joel Roth <joelz at pobox.com> wrote:
> >>
> >> Hey Joel,
> >>
> >> If you know the level, and you want to be explicit, you can try the
> >> default route syntax: '/media/*/*'.

Thanks. Will test this out.

> >> However, you will most likely prefer a regular expression (which you tried
> >> earlier), and Dancer allows that very easily since Perl considers regexes as
> >> first class:
> >> get qr/.../ => sub { ... };

Of course. I shouldn't have confined my thinking to the
cookbook/introduction. 

> >> We prefer to wrap qr() with something other than slashes, so we don't get
> >> into a backslash fight:
> >> get qr{ / media / (.*) }x => sub { ... };

\o/

>
> >> Enjoy!
> >>
> >>
> > I feel compelled to caution about how the use of regexs can open security
> > holes in your application.

Thanks for bringing this up.

> > Another way to go would be to traverse the directory(s) and generate routes
> > based on the findings in a before action.

That was how I had originally done it, one level only,
generating a page to represent the contents,
as a cron job.

A dynamic approach seemed easier, and suitable for this
small site.

Perhaps I'll go back to that, after trying out the regexen--
at least for my own satisfaction.

Thanks to all!

Joel

> 
> That's a good point and a good idea!
> 
> Thanks, Al!

-- 
Joel Roth


More information about the Dancer-users mailing list