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

John Napiorkowski jjn1056 at yahoo.com
Mon May 14 17:15:18 GMT 2007


--- 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');

I have this sort of thing in a lot of my logic, for
better or worse.  So I'd be partial to this continuing
to work.
--john


> 
> -- 
>       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/ 
> 
> _______________________________________________
> List:
>
http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
> Wiki: http://dbix-class.shadowcatsystems.co.uk/
> IRC: irc.perl.org#dbix-class
> SVN:
>
http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
> Searchable Archive:
>
http://www.mail-archive.com/dbix-class@lists.rawmode.org/
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the Dbix-class mailing list