Matt S Trout wrote:

> Try it. If it doesn't fail any tests, write ones that fail without it
> and we can ship it and see. Worst case we then unmerge part of your
> patch and invert the sense of the tests to ensure future generations
> of DBIC hackers don't make the same mistake :)

Here you are.

The actual patch is really simple.

Concerning the tests: I hope I got your instructions right... hope it's 
OK the way it is.
-- 
Bernhard Graf
Index: t/61findnot.t
===================================================================
--- t/61findnot.t	(revision 0)
+++ t/61findnot.t	(revision 0)
@@ -0,0 +1,46 @@
+use strict;
+use warnings;  
+
+use Test::More;
+use lib qw(t/lib);
+use DBICTest;
+
+my $schema = DBICTest->init_schema();
+
+plan tests => 17;
+
+my $art = $schema->resultset("Artist")->find(4);
+ok(!defined($art), 'Find on primary id: artist not found');
+my @cd = $schema->resultset("CD")->find(6);
+cmp_ok(@cd, '==', 1, 'Return something even in array context');
+ok(@cd && !defined($cd[0]), 'Array contains an undef as only element');
+
+$art = $schema->resultset("Artist")->find({artistid => '4'});
+ok(!defined($art), 'Find on unique constraint: artist not found');
[EMAIL PROTECTED] = $schema->resultset("CD")->find({artist => '2', title => 'Lada-Di Lada-Da'});
+cmp_ok(@cd, '==', 1, 'Return something even in array context');
+ok(@cd && !defined($cd[0]), 'Array contains an undef as only element');
+
+$art = $schema->resultset("Artist")->search({name => 'The Jesus And Mary Chain'});
+isa_ok($art, 'DBIx::Class::ResultSet', 'get a DBIx::Class::ResultSet object');
+my $next = $art->next;
+ok(!defined($next), 'Nothing next in ResultSet');
+my $cd = $schema->resultset("CD")->search({title => 'Rubbersoul'});
[EMAIL PROTECTED] = $cd->next;
+cmp_ok(@cd, '==', 1, 'Return something even in array context');
+ok(@cd && !defined($cd[0]), 'Array contains an undef as only element');
+
+$art = $schema->resultset("Artist")->single({name => 'Bikini Bottom Boys'});
+ok(!defined($art), 'Find on primary id: artist not found');
[EMAIL PROTECTED] = $schema->resultset("CD")->single({title => 'The Singles 1962-2006'});
+cmp_ok(@cd, '==', 1, 'Return something even in array context');
+ok(@cd && !defined($cd[0]), 'Array contains an undef as only element');
+
+$art = $schema->resultset("Artist")->search({name => 'Random Girl Band'});
+isa_ok($art, 'DBIx::Class::ResultSet', 'get a DBIx::Class::ResultSet object');
+$next = $art->single;
+ok(!defined($next), 'Nothing next in ResultSet');
+$cd = $schema->resultset("CD")->search({title => 'Call of the West'});
[EMAIL PROTECTED] = $cd->single;
+cmp_ok(@cd, '==', 1, 'Return something even in array context');
+ok(@cd && !defined($cd[0]), 'Array contains an undef as only element');
Index: lib/DBIx/Class/ResultSet.pm
===================================================================
--- lib/DBIx/Class/ResultSet.pm	(revision 3337)
+++ lib/DBIx/Class/ResultSet.pm	(working copy)
@@ -542,7 +542,7 @@
     $attrs->{where}, $attrs
   );
 
-  return (@data ? ($self->_construct_object(@data))[0] : ());
+  return (@data ? ($self->_construct_object(@data))[0] : undef);
 }
 
 # _is_unique_query
@@ -737,7 +737,7 @@
       ? @{delete $self->{stashed_row}}
       : $self->cursor->next
   );
-  return unless (@row);
+  return undef unless (@row);
   my ($row, @more) = $self->_construct_object(@row);
   $self->{stashed_objects} = [EMAIL PROTECTED] if @more;
   return $row;
_______________________________________________
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/[email protected]/

Reply via email to