}
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 };
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.
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);
}
=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;