[Dbix-class] Proposed DBIx::Class::Validate Changes
Aran Deltac
aran at arandeltac.com
Sun May 14 08:51:32 CEST 2006
On 5/12/06, Christopher H. Laco <claco at chrislaco.com> wrote:
> /claco arises from the land of the dead
>
> Now that I've ditched a majority of my distractions (a zillion email
> lists and rss feeds, irc, icq, im, etc), I've finally got a good
> foothold on the Handel redesign using DBIC schemas.
>
> So far so good; great in fact. One of the changes I'm making is to move
> towards using Validate as a replacement for the old CDBI constraints. A
> couple of hacks later; making my Exception/Constraint::check pretend to
> be FormValidator::Simple, everything is pretty much working. The only
> feature I can't replicate is the fact that CDBI constraints could
> actually change the column values if they needed to.
Initially this seems better suited for inflation/deflation. Do you
have examples of how this would be useful?
One example that comes to mind for me is some people like to store
phone numbers with only the digits - none of the formatting
characters. But, this is a case where I'd almost rather have a
deflator that could deflate to just digits no matter the format, and
inflate to a nicely formatted number.
> Since this is apparently not possible in the Validation module, I'd like
> to propose the following minor change:
>
> Allow validate() to call set_columns() with the \%data it already has
> upon success():
>
> > sub validate {
> > my $self = shift;
> > my %data = $self->get_columns();
> > my $module = $self->validation_module();
> > my $profile = $self->validation_profile();
> > my $result = $module->check( \%data => $profile );
> > if (blessed $result && $result->success()) {
> > $self->set_columns(\%data);
> > return $result;
> > } else {
> > $self->throw_exception( $result );
> > };
> > }
>
> I don't think that should effect anything else, but the tests will tell
Right, that wouldn't hurt anything as far as I know. But, it seems
like the wrong point in the logic to be updating fields through
validation.
> the story. If no one has any objections, I'll work up a patch.
That would be great if you can talk me in to it. :) Also, Matt wants
me to move Validate to a separate distro. I'll be doing that this
week.
Aran
More information about the Dbix-class
mailing list