From: Matt S Trout Date: Sun, 26 Feb 2006 04:03:29 +0000 (+0000) Subject: Fixup MANIFEST, rename 22cache -> 23cache, tweak to search X-Git-Tag: v0.06000~61^2~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3e0e9e276de1823691989e19575edc86658155f3;p=dbsrgits%2FDBIx-Class.git Fixup MANIFEST, rename 22cache -> 23cache, tweak to search --- diff --git a/MANIFEST b/MANIFEST index 4a03e0c..231a0a8 100644 --- 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 diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 4ab3389..2f80a43 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -155,7 +155,6 @@ call it as C. 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; diff --git a/maint/gen-schema.pl b/maint/gen-schema.pl index a4e101d..12b3aeb 100755 --- a/maint/gen-schema.pl +++ b/maint/gen-schema.pl @@ -5,6 +5,7 @@ use warnings; use lib qw(lib t/lib); use DBICTest; +use DBICTest::HelperRels; my $schema = DBICTest->initialise; diff --git a/t/basicrels/23cache.t b/t/basicrels/23cache.t index 1f8672a..ca2efee 100644 --- a/t/basicrels/23cache.t +++ b/t/basicrels/23cache.t @@ -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 index 0000000..73bc31a --- /dev/null +++ b/t/helperrels/23cache.t @@ -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); diff --git a/t/run/22cache.tl b/t/run/23cache.tl similarity index 100% rename from t/run/22cache.tl rename to t/run/23cache.tl