From: Matt S Trout Date: Thu, 1 Dec 2005 06:30:11 +0000 (+0000) Subject: Moved search to resultset, created ResultSetInstance X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0a3c5b435bb12d9cf11a403cb2933d106e8a0374;p=dbsrgits%2FDBIx-Class-Historic.git Moved search to resultset, created ResultSetInstance --- diff --git a/lib/DBIx/Class/Core.pm b/lib/DBIx/Class/Core.pm index 85b9fa3..7c3a1af 100644 --- a/lib/DBIx/Class/Core.pm +++ b/lib/DBIx/Class/Core.pm @@ -9,6 +9,7 @@ use base qw/DBIx::Class/; __PACKAGE__->load_components(qw/ InflateColumn Relationship + ResultSetInstance PK Row Table diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 999f322..4e69104 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -58,9 +58,9 @@ sub new { } my $new = { source => $db_class, - cols => $attrs->{cols} || [ $db_class->_select_columns ], + cols => $attrs->{cols}, cond => $attrs->{where}, - from => $attrs->{from} || $db_class->_table_name, + from => $attrs->{from}, count => undef, pager => undef, attrs => $attrs }; @@ -69,6 +69,34 @@ sub new { return $new; } +=item search + +Runs a search against the current resultset. + +=cut + +sub search { + my $self = shift; + + my $attrs = { %{$self->{attrs}} }; + if (@_ > 1 && ref $_[$#_] eq 'HASH') { + $attrs = { %{ pop(@_) } }; + } + + my $where = (@_ == 1 || ref $_[0] eq "HASH" ? shift: {@_}); + if (defined $where) { + $where = (defined $attrs->{where} + ? { '-and' => [ $where, $attrs->{where} ] } + : $where); + $attrs->{where} = $where; + } + + my $rs = $self->new($self->{source}, $attrs); + + return (wantarray ? $rs->all : $rs); +} + + =item cursor Return a storage driven cursor to the given resultset. diff --git a/lib/DBIx/Class/ResultSetInstance.pm b/lib/DBIx/Class/ResultSetInstance.pm new file mode 100644 index 0000000..9eefaa3 --- /dev/null +++ b/lib/DBIx/Class/ResultSetInstance.pm @@ -0,0 +1,7 @@ +package DBIx::Class::ResultSetInstance; + +use base qw/DBIx::Class/; + +sub search { shift->resultset->search(@_); } + +1; diff --git a/lib/DBIx/Class/Table.pm b/lib/DBIx/Class/Table.pm index 54a1684..16fc291 100644 --- a/lib/DBIx/Class/Table.pm +++ b/lib/DBIx/Class/Table.pm @@ -37,7 +37,9 @@ L objects. sub _register_columns { my ($class, @cols) = @_; my $names = { %{$class->_columns} }; - $names->{$_} ||= {} for @cols; + while (my $col = shift @cols) { + $names->{$col} = (ref $cols[0] ? shift : {}); + } $class->_columns($names); } @@ -114,20 +116,6 @@ no condition, =cut -sub search { - my $class = shift; - #warn "@_"; - my $attrs = { }; - if (@_ > 1 && ref $_[$#_] eq 'HASH') { - $attrs = { %{ pop(@_) } }; - } - $attrs->{where} = (@_ == 1 || ref $_[0] eq "HASH" ? shift: {@_}); - - my $rs = $class->resultset($attrs); - - return (wantarray ? $rs->all : $rs); -} - sub resultset { my $class = shift;