Fixup MANIFEST, rename 22cache -> 23cache, tweak to search
Matt S Trout [Sun, 26 Feb 2006 04:03:29 +0000 (04:03 +0000)]
MANIFEST
lib/DBIx/Class/ResultSet.pm
maint/gen-schema.pl
t/basicrels/23cache.t
t/helperrels/23cache.t [new file with mode: 0644]
t/run/23cache.tl [moved from t/run/22cache.tl with 100% similarity]

index 4a03e0c..231a0a8 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -88,7 +88,6 @@ lib/SQL/Translator/Parser/DBIx/Class.pm
 lib/SQL/Translator/Producer/DBIx/Class/File.pm
 Makefile.PL
 MANIFEST                       This list of files
-META.yml
 README
 t/02pod.t
 t/03podcoverage.t.disabled
@@ -122,8 +121,8 @@ t/basicrels/18self_referencial.t
 t/basicrels/19uuid.t
 t/basicrels/20unique.t
 t/basicrels/21serialize.t
-t/basicrels/22cache.t
 t/basicrels/22cascade_copy.t
+t/basicrels/23cache.t
 t/cdbi-sweet-t/08pager.t
 t/cdbi-t/01-columns.t
 t/cdbi-t/02-Film.t
@@ -165,6 +164,7 @@ t/helperrels/19uuid.t
 t/helperrels/20unique.t
 t/helperrels/21serialize.t
 t/helperrels/22cascade_copy.t
+t/helperrels/23cache.t
 t/lib/DBICTest.pm
 t/lib/DBICTest/BasicRels.pm
 t/lib/DBICTest/Extra.pm
@@ -212,8 +212,8 @@ t/run/18self_referencial.tl
 t/run/19uuid.tl
 t/run/20unique.tl
 t/run/21serialize.tl
-t/run/22cache.tl
 t/run/22cascade_copy.tl
+t/run/23cache.tl
 t/testlib/Actor.pm
 t/testlib/ActorAlias.pm
 t/testlib/Binary.pm
@@ -232,3 +232,4 @@ t/testlib/MyStarLinkMCPK.pm
 t/testlib/Order.pm
 t/testlib/OtherFilm.pm
 t/testlib/PgBase.pm
+META.yml
index 4ab3389..2f80a43 100644 (file)
@@ -155,7 +155,6 @@ call it as C<search({}, \%attrs);>.
 sub search {
   my $self = shift;
 
-  #use Data::Dumper;warn Dumper(@_);
   my $rs;
   if( @_ ) {
     
@@ -165,7 +164,14 @@ sub search {
      $attrs = { %$attrs, %{ pop(@_) } };
     }
 
-    my $where = (@_ ? ((@_ == 1 || ref $_[0] eq "HASH") ? shift : {@_}) : undef());
+    my $where = (@_
+                  ? ((@_ == 1 || ref $_[0] eq "HASH")
+                      ? shift
+                      : ((@_ % 2)
+                          ? $self->throw_exception(
+                              "Odd number of arguments to search")
+                          : {@_}))
+                  : undef());
     if (defined $where) {
       $where = (defined $attrs->{where}
                 ? { '-and' =>
@@ -377,13 +383,17 @@ Can be used to efficiently iterate over records in the resultset:
 
 sub next {
   my ($self) = @_;
-  my $cache = $self->get_cache;
-  if( @$cache ) {
+  my $cache;
+  if( @{$cache = $self->{all_cache} || []}) {
     $self->{all_cache_position} ||= 0;
     my $obj = $cache->[$self->{all_cache_position}];
     $self->{all_cache_position}++;
     return $obj;
   }
+  if ($self->{attrs}{cache}) {
+    $self->{all_cache_position} = 0;
+    return ($self->all)[0];
+  }
   my @row = $self->cursor->next;
 #  warn Dumper(\@row); use Data::Dumper;
   return unless (@row);
@@ -555,7 +565,7 @@ sub all {
     my @obj = map { $self->_construct_object(@$_); }
             $self->cursor->all;
     $self->set_cache( \@obj );
-    return @{ $self->get_cache };
+    return @obj;
   }
   return map { $self->_construct_object(@$_); }
            $self->cursor->all;
index a4e101d..12b3aeb 100755 (executable)
@@ -5,6 +5,7 @@ use warnings;
 use lib qw(lib t/lib);
 
 use DBICTest;
+use DBICTest::HelperRels;
 
 my $schema = DBICTest->initialise;
 
index 1f8672a..ca2efee 100644 (file)
@@ -3,5 +3,5 @@ use lib qw(t/lib);
 use DBICTest;
 use DBICTest::BasicRels;
 
-require "t/run/22cache.tl";
+require "t/run/23cache.tl";
 run_tests(DBICTest->schema);
diff --git a/t/helperrels/23cache.t b/t/helperrels/23cache.t
new file mode 100644 (file)
index 0000000..73bc31a
--- /dev/null
@@ -0,0 +1,7 @@
+use Test::More;
+use lib qw(t/lib);
+use DBICTest;
+use DBICTest::HelperRels;
+
+require "t/run/23cache.tl";
+run_tests(DBICTest->schema);
similarity index 100%
rename from t/run/22cache.tl
rename to t/run/23cache.tl