X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FTable.pm;h=49a9ffe82de1079c151a81fba8668efdac8fa425;hb=fe2b68754e7fdece29f77a8e7445ec504b862b83;hp=d370ce28a4e7097eb8c39d7ad01a121af4c1dbee;hpb=cda04c3afd46989e1964a6c8a277fd7faa11b291;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/Table.pm b/lib/DBIx/Class/Table.pm index d370ce2..49a9ffe 100644 --- a/lib/DBIx/Class/Table.pm +++ b/lib/DBIx/Class/Table.pm @@ -5,11 +5,13 @@ use warnings; use DBIx::Class::ResultSet; +use Carp qw/croak/; + use base qw/DBIx::Class/; -__PACKAGE__->load_components(qw/AccessorGroup/); +__PACKAGE__->load_components(qw/ResultSource AccessorGroup/); __PACKAGE__->mk_group_accessors('simple' => - qw/_columns name resultset_class result_class storage/); + qw/_columns _primaries name resultset_class result_class schema/); =head1 NAME @@ -19,90 +21,17 @@ DBIx::Class::Table - Table object =head1 DESCRIPTION -This class is responsible for defining and doing table-level operations on -L classes. +Table object that inherits from L =head1 METHODS -=cut - -sub new { - my ($class, $attrs) = @_; - $class = ref $class if ref $class; - my $new = bless($attrs || {}, $class); - $new->{resultset_class} ||= 'DBIx::Class::ResultSet'; - $new->{_columns} ||= {}; - $new->{name} ||= "!!NAME NOT SET!!"; - return $new; -} - -sub add_columns { - my ($self, @cols) = @_; - while (my $col = shift @cols) { - $self->add_column($col => (ref $cols[0] ? shift : {})); - } -} - -sub add_column { - my ($self, $col, $info) = @_; - $self->_columns->{$col} = $info || {}; -} - -=head2 add_columns - - $table->add_columns(qw/col1 col2 col3/); - - $table->add_columns('col1' => \%col1_info, 'col2' => \%col2_info, ...); +=head2 from -Adds columns to the table object. If supplied key => hashref pairs uses -the hashref as the column_info for that column. +Returns the FROM entry for the table (i.e. the table name) =cut -sub resultset { - my $self = shift; - my $rs_class = $self->resultset_class; - eval "use $rs_class;"; - return $rs_class->new($self); -} - -=head2 has_column - - if ($obj->has_column($col)) { ... } - -Returns 1 if the table has a column of this name, 0 otherwise. - -=cut - -sub has_column { - my ($self, $column) = @_; - return exists $self->_columns->{$column}; -} - -=head2 column_info - - my $info = $obj->column_info($col); - -Returns the column metadata hashref for a column. - -=cut - -sub column_info { - my ($self, $column) = @_; - die "No such column $column" unless exists $self->_columns->{$column}; - return $self->_columns->{$column}; -} - -=head2 columns - - my @column_names = $obj->columns; - -=cut - -sub columns { - die "columns() is a read-only accessor, did you mean add_columns()?" if (@_ > 1); - return keys %{shift->_columns}; -} +sub from { shift->name; } 1;