[Catalyst] Re: Validating single arg id

Bill Moseley moseley at hank.org
Sat Oct 17 23:34:43 GMT 2009


On Sat, Oct 17, 2009 at 12:50 PM, Aristotle Pagaltzis <pagaltzis at gmx.de>wro=
te:

> * iain <iainhubbard at googlemail.com> [2009-10-16 17:30]:
> > until we did this we had boilerplate validation at the top of
> > all the local actions.
>
> ++
>
> Bill, in another thread you asked me for an example of how
> Chained helps make things like complex auth checks more DRY. I=92ve
> been meaning to respond with an example out of my $job codebase,
> but until I get around to it, here=92s your hands-on example of
> something it=92d buy your codebase immediately. :-)
>

I meant to respond about that.  Perhaps I'm missing something, but the
chained example works great if there multiple actions that need to get at
that "Foo" object.  They can all chain back to the same root which validates
the id and then fetches the Foo object with that id and stuffs it into the
stash.

But, its often the case (well, my case) that there's only *one* action that
fetches Foo, but there's also single actions for find()ing a number of other
objects.  If I'm following the chained example correctly, then there would
be root for each -- Foo, Bar, Baz, and so on each running basically the same
validation.  I suppose the root can be written in a way to fetch many
different object types by inspecting the current action and thus the fetch
for Foo, Bar, Baz, etc. objects could all have the same root of the chain.

If I have many actions that do $c->model( $whatever )->find( $id ) and I
want to validate id doesn't it seems like find() (or really search_rs() )
would be the method to override?

Perhaps a better approach would be add a "safe_find()" as J. Shirley
suggested, but what good are methods if you don't override them. ;)



-- =

Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20091017/58146=
112/attachment.htm


More information about the Catalyst mailing list