Hi all,

According to the documentation for the in_storage method in DBIx::Class::Row 
http://search.cpan.org/~ribasushi/DBIx-Class/lib/DBIx/Class/Row.pm#in_storage

in_storage method should "Returns: 1|0"

In reality when row is not stored yet (e.g. returned by find_or_new method) or 
has been deleted the value returned by in_storage is undef.

Patch for DBIx/Class/Row.pm and tests attached.

Best Regards
Przemyslaw Kuznicki
Index: t/80unique.t
===================================================================
--- t/80unique.t	(revision 7813)
+++ t/80unique.t	(working copy)
@@ -195,7 +195,7 @@
       { key => 'cd_artist_title' }
     );
 
-    ok(!$cd1->in_storage, 'CD is not in storage yet after update_or_new');
+    is($cd1->in_storage, 0, 'CD is not in storage yet after update_or_new');
     $cd1->insert;
     ok($cd1->in_storage, 'CD got added to strage after update_or_new && insert');
 
Index: t/60core.t
===================================================================
--- t/60core.t	(revision 7813)
+++ t/60core.t	(working copy)
@@ -65,7 +65,7 @@
 
 is(@art, 2, 'And then there were two');
 
-ok(!$art->in_storage, "It knows it's dead");
+is($art->in_storage, 0, "It knows it's dead");
 
 dies_ok ( sub { $art->delete }, "Can't delete twice");
 
@@ -144,7 +144,7 @@
   });
 
   is($new_obj->name, 'find_or_new', 'find_or_new: instantiated a new artist');
-  ok(! $new_obj->in_storage, 'new artist is not in storage');
+  is($new_obj->in_storage, 0, 'new artist is not in storage');
 }
 
 my $cd = $schema->resultset("CD")->find(1);
Index: t/79aliasing.t
===================================================================
--- t/79aliasing.t	(revision 7813)
+++ t/79aliasing.t	(working copy)
@@ -52,7 +52,7 @@
   my $cd_rs = $schema->resultset('CD')->search({ 'artist.name' => 'Caterwauler McCrae' }, { join => 'artist' });
 
   my $cd = $cd_rs->find_or_new({ title => 'Huh?', year => 2006 });
-  ok(! $cd->in_storage, 'new CD not in storage yet');
+  is($cd->in_storage, 0, 'new CD not in storage yet');
   is($cd->title, 'Huh?', 'new CD title is correct');
   is($cd->year, 2006, 'new CD year is correct');
 }
Index: t/relationship/core.t
===================================================================
--- t/relationship/core.t	(revision 7813)
+++ t/relationship/core.t	(working copy)
@@ -133,7 +133,7 @@
   year => 2007,
 } );
 is( $cd->title, 'Greatest Hits 2: Louder Than Ever', 'find_or_new_related new record ok' );
-ok( ! $cd->in_storage, 'find_or_new_related on a new record: not in_storage' );
+is( $cd->in_storage, 0, 'find_or_new_related on a new record: not in_storage' );
 
 $cd->artist(undef);
 my $newartist = $cd->find_or_new_related( 'artist', {
Index: lib/DBIx/Class/Row.pm
===================================================================
--- lib/DBIx/Class/Row.pm	(revision 7813)
+++ lib/DBIx/Class/Row.pm	(working copy)
@@ -424,7 +424,7 @@
 sub in_storage {
   my ($self, $val) = @_;
   $self->{_in_storage} = $val if @_ > 1;
-  return $self->{_in_storage};
+  return ( defined $self->{_in_storage} ? $self->{_in_storage} : 0 );
 }
 
 =head2 update
@@ -554,7 +554,7 @@
     }
     $self->result_source->storage->delete(
       $self->result_source, $ident_cond);
-    $self->in_storage(undef);
+    $self->in_storage(0);
   } else {
     $self->throw_exception("Can't do class delete without a ResultSource instance")
       unless $self->can('result_source_instance');
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk

Reply via email to