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('_resultset_class' => 'DBIx::Class::ResultSet');
12 __PACKAGE__->mk_classdata('table_class' => 'DBIx::Class::Table');
14 sub iterator_class { shift->table_instance->resultset_class(@_) }
15 sub resultset_class { shift->table_instance->resultset_class(@_) }
16 sub _table_name { shift->table_instance->name }
20 DBIx::Class::TableInstance - provides a classdata table object and method proxies
24 __PACKAGE__->table('foo');
25 __PACKAGE__->add_columns(qw/id bar baz/);
26 __PACKAGE__->set_primary_key('id');
32 sub _mk_column_accessors {
33 my ($class, @cols) = @_;
34 $class->mk_group_accessors('column' => @cols);
39 __PACKAGE__->add_columns(qw/col1 col2 col3/);
41 Adds columns to the current class and creates accessors for them.
46 my ($class, @cols) = @_;
47 $class->table_instance->add_columns(@cols);
48 $class->_mk_column_accessors(@cols);
52 return shift->table_instance->columns;
57 __PACKAGE__->table('tbl_name');
59 Gets or sets the table name.
64 my ($class, $table) = @_;
65 return $class->table_instance->name unless $table;
67 $table = $class->table_class->new(
70 result_class => $class,
71 #storage => $class->storage,
73 if ($class->can('table_instance')) {
74 $table->{_columns} = { %{$class->table_instance->{_columns}||{}} };
77 $class->mk_classdata('table_instance' => $table);
82 $class->find_or_create({ key => $val, ... });
84 Searches for a record matching the search condition; if it doesn't find one,
85 creates one and returns that instead.
91 my $hash = ref $_[0] eq "HASH" ? shift: {@_};
92 my $exists = $class->find($hash);
93 return defined($exists) ? $exists : $class->create($hash);
98 if ($obj->has_column($col)) { ... }
100 Returns 1 if the class has a column of this name, 0 otherwise.
105 my ($self, $column) = @_;
106 return $self->table_instance->has_column($column);
111 my $info = $obj->column_info($col);
113 Returns the column metadata hashref for a column.
118 my ($self, $column) = @_;
119 return $self->table_instance->column_info($column);
124 my @column_names = $obj->columns;
129 return shift->table_instance->columns(@_);
136 Matt S. Trout <mst@shadowcatsystems.co.uk>
140 You may distribute this code under the same terms as Perl itself.