[Dbix-class] Deferred validation via accessors

Paul Makepeace paulm at paulm.com
Fri Jul 30 22:19:45 GMT 2010


On Fri, Jul 30, 2010 at 13:48, Rob Kinyon <rob.kinyon at gmail.com> wrote:
> On Fri, Jul 30, 2010 at 16:31, Paul Makepeace <paulm at paulm.com> wrote:
>> I'm hoping to use custom accessors to do some validation of incoming
>> data with reference to existing column data.
>
> [snip lots of explanation that isn't helping much]
>
> Why on earth are you setting stuff manually? It's obvious...

(Without the condescending tone it just wouldn't get through their
thick skull, right?)

> So, code _THOSE_ up and
> have those do the right settings for foo_enabled, bar_enabled, and
> default_view. If someone wants to set things to "illegal" values, they
> should be able to. But, you'll be able to find those very easily with
> grep because they're the only ones actually using foo_enabled,
> bar_enabled, and/or default_view. All code outside the ResultSource
> should use set_view_to() or whatever.

I'd be interested to hear what you think that abstracted method would be called.

I'm not seeing an abstraction that simultaneously requires setting two
booleans and a string to the name of one of them that doesn't end up
being clunky or overly magical. On top of that, requires extra work in
the controller presenting those vars from the form to the model.

Compare,

  $r->foo_enabled(..params('foo_enabled'));
  $r->bar_enabled(..params('foo_enabled'));
  $r->default_view(..params('default_view'));

with,

  $r->wtf(foo => ..params('foo_enabled'), bar =>
..params('foo_enabled'), default_view => ..params('default_view'));

Not horrid, but definitely 'meh', and nothing's occurring to me at all
what "wtf" should be called.

Oh, and there's still having to override the accessors to die on any
attempt to set a value thru' them.

Catching the update is looking pretty good.

Paul

> Remember - all problems are solvable by adding an additional layer of
> abstraction (except, of course, the problem of too many layers of
> abstraction).
>
> --
> Thanks,
> Rob Kinyon
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
>



More information about the DBIx-Class mailing list