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

Bernhard Graf dbic3 at augensalat.de
Mon May 14 08:57:24 GMT 2007


Matt S Trout wrote:

> >   do_something($alpha, $rs->find($id), $omega);
>
> I always do
>
> if (my $obj = $rs->find(...)) {
>
> for clarity.

You mean you'd do:

  if (my $obj = $rs->find(...)) {
     do_something($alpha, $obj, $omega);
  } else {
     do_something($alpha, $obj, $omega);
  }

? Fortunately TIMTOWTDI. ;-)

> > 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.
>
> Depends really - is it worth giving up consistency to support the
> poor programming practice exemplified above?

Why is that poor?

> Opinions welcome, I'm not -overly- troubled either way although by
> default I'd say the current conceptual consistency is the correct
> answer.

At least documentation should clarify the fact, that find() returns a 
list of row objects, that either has 1 or 0 elements.

-- 
Bernhard Graf



More information about the Dbix-class mailing list