1 package DBIx::Class::TableInstance;
6 use base qw/DBIx::Class/;
7 use DBIx::Class::Table;
9 __PACKAGE__->mk_classdata('table_alias'); # FIXME: Doesn't actually do anything yet!
11 __PACKAGE__->mk_classdata('table_class' => 'DBIx::Class::Table');
13 sub iterator_class { shift->result_source->resultset_class(@_) }
14 sub resultset_class { shift->result_source->resultset_class(@_) }
15 sub _table_name { shift->result_source->name }
19 DBIx::Class::TableInstance - provides a classdata table object and method proxies
23 __PACKAGE__->table('foo');
24 __PACKAGE__->add_columns(qw/id bar baz/);
25 __PACKAGE__->set_primary_key('id');
31 sub _mk_column_accessors {
32 my ($class, @cols) = @_;
33 $class->mk_group_accessors('column' => @cols);
38 __PACKAGE__->add_columns(qw/col1 col2 col3/);
40 Adds columns to the current class and creates accessors for them.
45 my ($class, @cols) = @_;
46 $class->result_source->add_columns(@cols);
47 $class->_mk_column_accessors(@cols);
51 return shift->result_source->columns;
56 __PACKAGE__->table('tbl_name');
58 Gets or sets the table name.
63 my ($class, $table) = @_;
64 return $class->result_source->name unless $table;
66 $table = $class->table_class->new(
69 result_class => $class,
71 if ($class->can('result_source')) {
72 $table->{_columns} = { %{$class->result_source->{_columns}||{}} };
75 $class->mk_classdata('result_source' => $table);
76 if ($class->can('schema_instance')) {
77 $class =~ m/([^:]+)$/;
78 $class->schema_instance->register_class($class, $class);
84 if ($obj->has_column($col)) { ... }
86 Returns 1 if the class has a column of this name, 0 otherwise.
91 my ($self, $column) = @_;
92 return $self->result_source->has_column($column);
97 my $info = $obj->column_info($col);
99 Returns the column metadata hashref for a column.
104 my ($self, $column) = @_;
105 return $self->result_source->column_info($column);
110 my @column_names = $obj->columns;
115 return shift->result_source->columns(@_);
118 sub set_primary_key { shift->result_source->set_primary_key(@_); }
119 sub primary_columns { shift->result_source->primary_columns(@_); }
125 Matt S. Trout <mst@shadowcatsystems.co.uk>
129 You may distribute this code under the same terms as Perl itself.