[Catalyst] Adding CaptureArgs for the whole controller?

Lukas Thiemeier spamcatcher at thiemeier.net
Tue Apr 2 20:44:41 GMT 2013

On 04/02/2013 10:07 PM, Alex Povolotsky wrote:
> Hello!
> I'm implementing some sort of simple CRM, and I'd like to handle a chain
> like
> /domain/*/service/*/edit with controller
> App::Controller::Domain::Service, not with App::Controller::Domain
> How can I set CaptureArgs for the whole
> App::Controller::Domain::Service? I'd like to handle captured arg
> somewhere in begin or auto
> Alex
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/


short answer: you can't!

Args and CaptureArgs are always specific to an action. It is not
possible (and doesn't make sense)  to define CaptureArgs for the whole


You can create a empty action, and chain all actions in your controller
to that actions, like this:

  sub mybase :Chained("/") :PathPart("") :CaptureArgs(2) {};

  sub foo :Chained('mybase') Args(0){
	#do foo

  sub bar :Chained('mybase') Args(0){
	# do bar

You can even create a BUILDARGS method which ensures that all your
actions are chained to that base action (if you don't want to do this by
yourself). But I would not recomment this.

If you realy  want to process your args and capture args in begin or
auto (for whatever reason) you can just do so. Args can be found in
$c->req->arguments and captures in $c->req->captures.

cheers, Lukas

More information about the Catalyst mailing list