[Dbix-class] Re: Return value of DBIx::Class::ResultSet::find()
A. Pagaltzis
pagaltzis at gmx.de
Tue May 15 02:05:52 GMT 2007
* A. Pagaltzis <pagaltzis at gmx.de> [2007-05-15 02:35]:
> * Matt S Trout <dbix-class at trout.me.uk> [2007-05-14 18:45]:
> > On Mon, May 14, 2007 at 09:15:18AM -0700, John Napiorkowski wrote:
> > > 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.
>
> No. The left-hand side of a boolean op is always in scalar context.
PS.: what you’re saying there *can* be expressed:
( my ( $result ) = $dbic->resultset( 'MyApp' )->find( xxx ) ) || ...;
That makes the assignment as a whole the left-hand side of the
boolean op, so the right-hand side of the assignment is not
affected by the boolean op’s enforced scalar context.
And this would indeed break if `find` returns undef explicitly,
because the return value of a list assignment in scalar context
is the number of rvalue elements, which would be 1 when an undef
is returned.
Regards,
--
Aristotle Pagaltzis // <http://plasmasturm.org/>
More information about the Dbix-class
mailing list