[Dbix-class] Return value of DBIx::Class::ResultSet::find()

Bernhard Graf dbic3 at augensalat.de
Sun May 13 21:25:16 GMT 2007


Documentation tells that DBIx::Class::ResultSet::find() returns a row 
object.

What it does not tell is what is returned if no row is found. Actually 
it returns an empty list in list context - not an undef as one might 
expect.

While the difference between empty list and undef is usually not 
important, it can lead to confusing results if find() is called as 
subroutine argument:

  do_something($alpha, $rs->find($id), $omega);

meaning do_something() is called with three arguments if find() succeeds 
and two arguments if it fails.

So since find() is not designed to return lists, to be consistent it 
should always return a single value: either a row object or undef.

Objections?
-- 
Bernhard Graf



More information about the Dbix-class mailing list