Moved search to resultset, created ResultSetInstance
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Table.pm
index 42631de..16fc291 100644 (file)
@@ -4,9 +4,8 @@ use strict;
 use warnings;
 
 use DBIx::Class::ResultSet;
-use Data::Page;
 
-use base qw/Class::Data::Inheritable/;
+use base qw/DBIx::Class/;
 
 __PACKAGE__->mk_classdata('_columns' => {});
 
@@ -38,7 +37,9 @@ L<DBIx::Class> 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); 
 }
 
@@ -100,24 +101,20 @@ 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 });
 
-=cut
+To retrieve all rows, simply call C<search()> with no condition parameter,
 
-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);
-}
+  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 resultset {
   my $class = shift;
@@ -174,6 +171,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;