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->table_instance->resultset_class(@_) }
14 sub resultset_class { shift->table_instance->resultset_class(@_) }
15 sub _table_name { shift->table_instance->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->table_instance->add_columns(@cols);
47 $class->_mk_column_accessors(@cols);
51 return shift->table_instance->columns;
56 __PACKAGE__->table('tbl_name');
58 Gets or sets the table name.
63 my ($class, $table) = @_;
64 return $class->table_instance->name unless $table;
66 $table = $class->table_class->new(
69 result_class => $class,
71 if ($class->can('table_instance')) {
72 $table->{_columns} = { %{$class->table_instance->{_columns}||{}} };
75 $class->mk_classdata('table_instance' => $table);
80 $class->find_or_create({ key => $val, ... });
82 Searches for a record matching the search condition; if it doesn't find one,
83 creates one and returns that instead.
89 my $hash = ref $_[0] eq "HASH" ? shift: {@_};
90 my $exists = $class->find($hash);
91 return defined($exists) ? $exists : $class->create($hash);
96 if ($obj->has_column($col)) { ... }
98 Returns 1 if the class has a column of this name, 0 otherwise.
103 my ($self, $column) = @_;
104 return $self->table_instance->has_column($column);
109 my $info = $obj->column_info($col);
111 Returns the column metadata hashref for a column.
116 my ($self, $column) = @_;
117 return $self->table_instance->column_info($column);
122 my @column_names = $obj->columns;
127 return shift->table_instance->columns(@_);
131 return shift->table_instance(@_);
134 sub set_primary_key { shift->table_instance->set_primary_key(@_); }
135 sub primary_columns { shift->table_instance->primary_columns(@_); }
141 Matt S. Trout <mst@shadowcatsystems.co.uk>
145 You may distribute this code under the same terms as Perl itself.