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

Matt S Trout dbix-class at trout.me.uk
Mon May 14 17:38:49 GMT 2007


On Mon, May 14, 2007 at 09:15:18AM -0700, John Napiorkowski wrote:
> 
> --- Matt S Trout <dbix-class at trout.me.uk> wrote:
> 
> > On Mon, May 14, 2007 at 09:57:24AM +0200, Bernhard
> > Graf wrote:
> > > 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);
> > >   }
> > 
> > I can't really see somewhere I'd have an API that
> > wanted that, to be honest.
> > 
> > Optional parameters in the middle of the argument
> > list strike me as a
> > design smell.
> > 
> > > > 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.
> > 
> > A doc patch is definitely in order whether we change
> > the behaviour or not.
> > 
> > My worry is people doing if and getting the return
> > in list context, hence
> > seeing a returned undef as true, but equally I can
> > see the convenience value
> > of changing the behaviour.
> > 
> > C'mon people, pitch in with arguments and opinions
> > :)
> 
> I'm personally attached to the following syntax:
> 
> my $result = $dbic->resultset('MyApp')->find(xxx) ||
> $self->throw('Not Found Type Error');

That'll still work whatever. What would break is

my ($result) = ($dbic->resultset('MyApp')->find(xxx)) || ...;

I suspect.

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director    Want a managed development or deployment platform?
 Shadowcat Systems Ltd.  Contact mst (at) shadowcatsystems.co.uk for a quote
http://chainsawblues.vox.com/             http://www.shadowcatsystems.co.uk/ 



More information about the Dbix-class mailing list