1 package DBIx::Class::Table;
6 use DBIx::Class::ResultSet;
10 use base qw/DBIx::Class/;
11 __PACKAGE__->load_components(qw/AccessorGroup/);
13 __PACKAGE__->mk_group_accessors('simple' =>
14 qw/_columns name resultset_class result_class storage/);
18 DBIx::Class::Table - Table object
24 This class is responsible for defining and doing table-level operations on
25 L<DBIx::Class> classes.
32 my ($class, $attrs) = @_;
33 $class = ref $class if ref $class;
34 my $new = bless($attrs || {}, $class);
35 $new->{resultset_class} ||= 'DBIx::Class::ResultSet';
36 $new->{_columns} ||= {};
37 $new->{name} ||= "!!NAME NOT SET!!";
42 my ($self, @cols) = @_;
43 while (my $col = shift @cols) {
44 $self->add_column($col => (ref $cols[0] ? shift : {}));
49 my ($self, $col, $info) = @_;
50 $self->_columns->{$col} = $info || {};
55 $table->add_columns(qw/col1 col2 col3/);
57 $table->add_columns('col1' => \%col1_info, 'col2' => \%col2_info, ...);
59 Adds columns to the table object. If supplied key => hashref pairs uses
60 the hashref as the column_info for that column.
66 my $rs_class = $self->resultset_class;
67 eval "use $rs_class;";
68 return $rs_class->new($self);
73 if ($obj->has_column($col)) { ... }
75 Returns 1 if the table has a column of this name, 0 otherwise.
80 my ($self, $column) = @_;
81 return exists $self->_columns->{$column};
86 my $info = $obj->column_info($col);
88 Returns the column metadata hashref for a column.
93 my ($self, $column) = @_;
94 croak "No such column $column" unless exists $self->_columns->{$column};
95 return $self->_columns->{$column};
100 my @column_names = $obj->columns;
105 croak "columns() is a read-only accessor, did you mean add_columns()?" if (@_ > 1);
106 return keys %{shift->_columns};
113 Matt S. Trout <mst@shadowcatsystems.co.uk>
117 You may distribute this code under the same terms as Perl itself.