X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FTable.pm;h=34e926e0729da5aee17235ff05700da96aed10d1;hb=1edd17220a3f0fa2768084572d8ca57cfc2a2fcc;hp=42631ded9ac97b3ceac7719394d56b4698d6ae4d;hpb=3c5b25c5328c41ff6fb062bf2aed446263cf01ec;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Table.pm b/lib/DBIx/Class/Table.pm index 42631de..34e926e 100644 --- a/lib/DBIx/Class/Table.pm +++ b/lib/DBIx/Class/Table.pm @@ -6,7 +6,7 @@ use warnings; use DBIx::Class::ResultSet; use Data::Page; -use base qw/Class::Data::Inheritable/; +use base qw/DBIx::Class/; __PACKAGE__->mk_classdata('_columns' => {}); @@ -100,9 +100,19 @@ sub count { =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 with no condition parameter, + + my @all = $class->search(); # equivalent to search({}) + +If you need to pass in additional attributes (see +L 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 { @@ -174,6 +184,39 @@ sub find_or_create { return defined($exists) ? $exists : $class->create($hash); } +=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}; +} + +=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}; +} + +=item columns + + my @column_names = $obj->columns; + +=cut + sub columns { return keys %{shift->_columns}; } 1;