1 package DBIx::Class::Table;
6 use DBIx::Class::ResultSet;
8 use base qw/DBIx::Class/;
9 __PACKAGE__->load_components(qw/AccessorGroup/);
11 __PACKAGE__->mk_group_accessors('simple' =>
12 qw/_columns name resultset_class result_class storage/);
16 DBIx::Class::Table - Table object
22 This class is responsible for defining and doing table-level operations on
23 L<DBIx::Class> classes.
30 my ($class, $attrs) = @_;
31 $class = ref $class if ref $class;
32 my $new = bless($attrs || {}, $class);
33 $new->{resultset_class} ||= 'DBIx::Class::ResultSet';
34 $new->{_columns} ||= {};
35 $new->{name} ||= "!!NAME NOT SET!!";
40 my ($self, @cols) = @_;
41 while (my $col = shift @cols) {
42 $self->add_column($col => (ref $cols[0] ? shift : {}));
47 my ($self, $col, $info) = @_;
48 $self->_columns->{$col} = $info || {};
53 $table->add_columns(qw/col1 col2 col3/);
55 $table->add_columns('col1' => \%col1_info, 'col2' => \%col2_info, ...);
57 Adds columns to the table object. If supplied key => hashref pairs uses
58 the hashref as the column_info for that column.
64 my $rs_class = $self->resultset_class;
65 eval "use $rs_class;";
66 return $rs_class->new($self);
71 if ($obj->has_column($col)) { ... }
73 Returns 1 if the table has a column of this name, 0 otherwise.
78 my ($self, $column) = @_;
79 return exists $self->_columns->{$column};
84 my $info = $obj->column_info($col);
86 Returns the column metadata hashref for a column.
91 my ($self, $column) = @_;
92 die "No such column $column" unless exists $self->_columns->{$column};
93 return $self->_columns->{$column};
98 my @column_names = $obj->columns;
103 die "columns() is a read-only accessor, did you mean add_columns()?" if (@_ > 1);
104 return keys %{shift->_columns};
111 Matt S. Trout <mst@shadowcatsystems.co.uk>
115 You may distribute this code under the same terms as Perl itself.