[Dbix-class] Scalar ref update()'s

Marc Mims marc at questright.com
Fri May 16 18:41:03 BST 2008


* Jose Fonseca <zefonseca at gmail.com> [080516 10:30]:
> A technical solution would involve what Ash called "too much magic", and I
> sort of agree**. Also keeping it in 2 functions would keep the system well
> decoupled instead of bloating it up(TMM again).
>
> [snip]
>
> ** The reason I don't agree completely is that, as explained above,
> returning the scalar ref does not make any sense at all in update(). In my
> opinion if we create a 2nd function, we should throw an immediate exception
> when update is used with a scalar ref value to force it to break early and
> let the developer know it's being used incorrectly. In my case I just wrote
> that code assuming I'd get the date back because that scalar ref has nothing
> to be doing in my Perl code.

Having given it some thought, I completely agree that it's too much
magic.  It may, in fact, be undesirable in some circumstances.  For
instance, I might want to set a column to \'NOW()' and have repeated,
future updates bump the timestamp without having to explicitly set the
timestamp column each time.

So, reading the value from the DB should only be done at the user's
request.  An update_and_refresh might be handy, but it's really not
necessary.  Since update returns $self, you could just:

    $row->update->discard_changes;

	-Marc



More information about the DBIx-Class mailing list