[Catalyst] Multiple actions matching a request - what happens?

Gianni Ceccarelli dakkar at thenautilus.net
Thu Mar 1 14:38:23 GMT 2012

Imagine you have a set of actions that match the same request. Maybe
they have the same :Path, or maybe you're using
Catalyst::ActionRole::MatchRequestMethod or something similar, and you

  sub post_foo :Path('foo') Method('POST') { }
  sub other_foo :Path('foo') { }

intending for the 'other_foo' action to be invoked when the method is
not POST.

This will sometimes work and sometimes not. I have dug a bit in the
source, and it looks like this:

- Catalyst::Controller::register_actions calls

  - which gets the methods from

  - which sorts the method it returns in the order they were declared

- register_actions will call register_action_methods which will call
  Catalyst::Dispatcher::register for each method in the order they
  were received

- the Dispatcher will register the action with every DispatchType that
  wants it

- Catalyst::DispatchType::Path sorts actions by
  Catalyst::Action::compare, that is, by Args count

- which essentially means that if you have two Path actions for the
  same Path, and both match, which one gets called is
  implementation-dependent (at the moment, it looks like the last one
  declared will win)

Now, this may or may not be a problem. I have a work-around: rework
the controller to have the actions be :Path(''), then use a :Default
action to catch "everything else".

On the other hand, maybe I'm not the only one doing such crazy things
with the dispatcher, and maybe we could add a :Priority($number)
attribute to actions, and have the Catalyst::Action::compare method
use it to break ties.

Did I make any sense?

	Dakkar - <Mobilis in mobile>
	GPG public key fingerprint = A071 E618 DD2C 5901 9574
	                             6FE2 40EA 9883 7519 3F88
	                    key id = 0x75193F88

Most discipline is hidden discipline, designed not to liberate but to
limit. Do not ask Why?  Be cautious with How?  Why? leads inexorably to
paradox. How? traps you in a universe of cause and effect.  Both deny
the infinite. 

  -- The Apocrypha of Arrakis
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
Url : http://lists.scsys.co.uk/pipermail/catalyst/attachments/20120301/138c09bf/signature.pgp

More information about the Catalyst mailing list