Dear monks,

is there a sane way how to get rid of "unnecessary" part of URL path, while avoiding the matching conflict? Imagine chained URLs (paths) like:

/region/REGION /category/CATEGORY /region/REGION/.... /category/CATEGORY/...
It is easy to implement them as chained URIs
sub load_region : Chained('/') : PathPart('region') : CaptureArgs(1) { ... } sub view_region : Chained('load_region') : PathPart('') : Args(0) { ... } sub load_category : Chained('/') : PathPart('category') : CaptureArgs( +1) { ... } sub view_category : Chained('load_category') : PathPart('') : Args(0) +{ ... }

Now I would like to get rid of region and category path parts. The range of values for REGION and CATEGORY are disjunct and the values are known so I know that /czech deals with region, while /cosmetics is about category. I can strip the PathPart.

sub load_region : Chained('/') : PathPart('') : CaptureArgs(1) { ... } sub view_region : Chained('load_region') : PathPart('') : Args(0) { ... } sub load_region : Chained('/') : PathPart('') : CaptureArgs(1) { ... } sub view_region : Chained('load_region') : PathPart('') : Args(0) { ... }

but it leads to the conflict, because there is no code to resolve whether the first path part is region or category.

Earlier I tried to redefine match on load_region, but unsuccessfully. As far as I understand Catalyst::DispatchType::Chained the $action->match is called only for the last action of the chain, i.e on view_region.

Do you know any way how to enforce matching on captures for intermediate actions of the chain?

I think that this type of URLs is quite common, for example URLs where the first part of path is a language.

I appreciate any advice including why it is unwise to strip path parts.


In reply to Catalyst - chained actions with empty PathPart by roman

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.