Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Users

Multiple actions matching a request - what happens?

 

 

Catalyst users RSS feed   Index | Next | Previous | View Threaded


dakkar at thenautilus

Mar 1, 2012, 6:38 AM

Post #1 of 1 (158 views)
Permalink
Multiple actions matching a request - what happens?

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
do:

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
Catalyst::Controller::get_action_methods

- which gets the methods from
MooseX::MethodAttributes::Role::Meta::Class::get_nearest_methods_with_attributes

- 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
Attachments: signature.asc (0.19 KB)

Catalyst users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.