[Catalyst] creating action classes for chained actions, trouble with overriding ->match

Matt S Trout dbix-class at trout.me.uk
Wed May 9 15:16:49 GMT 2007


On Tue, May 08, 2007 at 02:04:01PM -0700, John Napiorkowski wrote:
> 
> --- Matt S Trout <dbix-class at trout.me.uk> wrote:
> 
> > On Tue, Mar 20, 2007 at 01:15:48PM -0700, John
> > Napiorkowski wrote:
> > > I may have answered my own question.  A peer
> > pointed me to:
> > > 
> > >
> >
> http://search.cpan.org/src/MRAMBERG/Catalyst-Runtime-5.7007/lib/Catalyst/DispatchType/Chained.pm
> > > 
> > > and down in a method called 'recurse_match' it
> > does indeed seem like match is only called against
> > the endpoint in a chain.  So I guess I'd like to
> > find out if anyone knows the reasoning behind this. 
> > I think ideally if an action class can over ride
> > match, this should be allowed for all types of
> > actions.  Or I am just not smart enough to know why
> > not :)
> > 
> > Because nobody's implemented match_captures yet
> > which Chained and Regex could
> > then both call. Should be pretty easy if you fancy a
> > go.
> 
> Let me see if I understand what the scope of this and
> the effect would be.
> 
> We'd want a new method on Catalyst::ActionChain called
> match_captures which could look something like

On C::Action, not ::ActionChain.
 
> sub match_captures
> {
>    my ( $self, $c, @cap_args ) = @_;
>    return 1; ## or 0 to fail to match.
> }
> 
> Where @cap_args would the actual capture specified via
> the attribute 'CaptureArgs(x)'
> 
> We'd need to patch this into (I'm guessing) the
> recurse_match method for chained dispatch type to make
> sure we call this new match method.
> 
> Then if you wanted an actionclass for chained actions
> that are not endpoints you'd inherit from
> Catalyst::ActionChain instead of Catalyst::Action

See previous comment.

> I'm a bit confused about using this for Regex since
> from the source it looks like that dispatch type is
> calling the regular match.  Could you please enlighten
> me as to your thinking here?

For a regex match you'd call both - match_captures to
match anything captured via $1, $2 etc. and match to match
the @args.

> I can see this would work although I am concerned
> (maybe for no good reason) that action classes with
> match methods wouldn't work as expected if the action
> is in the middle of a chain.  So this would reduce re
> usability for those action classes.  However this may
> not be a problem.  Any thoughts on that?

Hmm. I'm not entirely sure how best to deal with that - perhaps a
match_any method which match and match_captures both call by default. The
trouble is that a single action can have captures as well as args so I can't
see any alternative to having the two methods. You make a good point though
- I wonder if just having match() called in all cases -would- work.

Perhaps we should try it and see :)

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director    Want a managed development or deployment platform?
 Shadowcat Systems Ltd.  Contact mst (at) shadowcatsystems.co.uk for a quote
http://chainsawblues.vox.com/             http://www.shadowcatsystems.co.uk/ 



More information about the Catalyst mailing list