I'm trying to write a Catalyst Controller that matches a specific path but with a single optional argument. This seems like something that would be perfect for Regex
, but this is deprecated, and I can't figure out how to use Chained to accomplish this. Also, I don't really want to have multiple methods, which is how Chained seems to work--I just want one.
(I see that there's been a previous discussion of this at what is the best way to hanlde optional url arguments in a Catalyst controller?, but this is from nine years ago, and it's still not clear to me.)
All I'm trying to do is match a path which can have exactly four or five arguments. I'm using Catalyst::Controller::REST, if that affects things.
sub review : Path('/review') : Args(4) : ActionClass('REST') {}
sub review_GET {
my ( $self, $c, $catalog_id, $item_id, $order_no, $event_id, $OPTIONAL_SOMETHING_ELSE) = @_;
# do stuff...
}
That's basically it. If I have a plain Args()
, then I can match any number of arguments, but I don't want this: I want to match only four or five arguments. (I don't need to worry about type constraints; I handle that in code.) But the processing of this should be the same; I don't want to have a totally different method to handle the four-argument vs. the five-argument call, which seems to be how Chained
would work. The same would go for having two methods, one with Args(4)
and one with Args(5)
--they shouldn't be separated.
Thanks.