Here's another thought.

If you mistakenly did the following.

my $row = $schema->resultset('MyTable')->search({
   col => 'some value',
});

Rather than

my $row = $schema->resultset('MyTable')->search({
   col => 'some value',
})->first;

Then your

$row->update({attr => 'stuff', foo => 'bar', ultimate_answer => 42});

Would apply the update not to one row (as intended) but the entire resultset.

Wheras

$row->attr('stuff');
$row->foo('bar');
$row->ultimate_answer(42);
$row->update;

Would give you a runtime error

Can't locate object method "attr" via package "DBIx::Class::ResultSet"

This might be more desirable than silently updating multiple (all?) records in your database!

Regards
Ian


On 07/04/2010 22:47, Nathaniel Green wrote:
Thanks for the response, Caleb. You do make a good point about readability.

The best justification I could come up with was that using the
accessors encapsulates the object better, allowing you to later change
the underlying implementation without having to change update calls.
But that seems a rare case.

Any other thoughts?

Thanks,
Nate


On Wed, Apr 7, 2010 at 3:45 PM, Caleb Cushing<[email protected]>  wrote:
On Tue, Apr 6, 2010 at 12:46 PM, Nathaniel Green<[email protected]>  wrote:
$row->update({ attr =>  'stuff', foo =>  'bar', ultimate_answer =>  42 });


There may be another reason but the latter is more readable... however

$row->update({
    attr =>  'stuff',
    foo =>  'bar',
    ultimate_answer =>  42,
});

that isn't less readable and it's as easy as the other to update.
where your one liner makes it a little bit harder to see changes if
you change it... and you need to diff the change.

just my 2 cents. probably more justification for the other way elsewhere.
--
Caleb Cushing

http://xenoterracide.blogspot.com

_______________________________________________
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/[email protected]


_______________________________________________
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/[email protected]




_______________________________________________
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/[email protected]

Reply via email to