use DBIx::Class::ResultSet;
use Data::Page;
-use base qw/Class::Data::Inheritable/;
+use base qw/DBIx::Class/;
__PACKAGE__->mk_classdata('_columns' => {});
__PACKAGE__->mk_classdata('_resultset_class' => 'DBIx::Class::ResultSet');
-__PACKAGE__->mk_classdata('_page_object');
-
sub iterator_class { shift->_resultset_class(@_) }
=head1 NAME
=item search
- my @obj = $class->search({ foo => 3 });
+ my @obj = $class->search({ foo => 3 }); # "... WHERE foo = 3"
my $cursor = $class->search({ foo => 3 });
+To retrieve all rows, simply call C<search()> with no condition parameter,
+
+ my @all = $class->search(); # equivalent to search({})
+
+If you need to pass in additional attributes (see
+L<DBIx::Class::ResultSet/Attributes> for details) an empty hash indicates
+no condition,
+
+ my @all = $class->search({}, { cols => [qw/foo bar/] }); # "SELECT foo, bar FROM $class_table"
+
=cut
sub search {
}
$attrs->{where} = (@_ == 1 || ref $_[0] eq "HASH" ? shift: {@_});
- # for pagination, we create the resultset with no limit and slice it later
- my $page = {};
- if ( $attrs->{page} ) {
- map { $page->{$_} = $attrs->{$_} } qw/rows page/;
- delete $attrs->{$_} for qw/rows offset page/;
- }
-
my $rs = $class->resultset($attrs);
- if ( $page->{page} ) {
- my $pager = Data::Page->new(
- $rs->count,
- $page->{rows} || 10,
- $page->{page} || 1 );
- $class->_page_object( $pager );
- return $rs->slice( $pager->skipped,
- $pager->skipped + $pager->entries_per_page - 1 );
- }
-
return (wantarray ? $rs->all : $rs);
}
return defined($exists) ? $exists : $class->create($hash);
}
-sub columns { return keys %{shift->_columns}; }
-
-=item page
+=item has_column
+
+ if ($obj->has_column($col)) { ... }
+
+Returns 1 if the object has a column of this name, 0 otherwise
+
+=cut
+
+sub has_column {
+ my ($self, $column) = @_;
+ return exists $self->_columns->{$column};
+}
- $pager = $class->page;
-
-Returns a Data::Page object for the most recent search that was performed
-using the page parameter.
+=item column_info
+
+ my $info = $obj->column_info($col);
+
+Returns the column metadata hashref for the column
+
+=cut
+
+sub column_info {
+ my ($self, $column) = @_;
+ die "No such column $column" unless exists $self->_columns->{$column};
+ return $self->_columns->{$column};
+}
-=cut
+=item columns
+
+ my @column_names = $obj->columns;
+
+=cut
-sub page { shift->_page_object }
+sub columns { return keys %{shift->_columns}; }
1;