On Sat, Oct 17, 2009 at 12:50 PM, Aristotle Pagaltzis <pagalt...@gmx.de>wrote:
> * iain <iainhubb...@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’ve > been meaning to respond with an example out of my $job codebase, > but until I get around to it, here’s your hands-on example of > something it’d 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 mose...@hank.org
_______________________________________________ List: Catalyst@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/