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');
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);
50 sub resultset_instance {
52 my $table = $class->table_instance->new($class->table_instance);
53 $table->storage($class->storage_instance);
54 $table->result_class($class);
55 return $table->resultset;
59 return shift->table_instance->columns;
64 __PACKAGE__->table('tbl_name');
66 Gets or sets the table name.
71 my ($class, $table) = @_;
72 return $class->table_instance->name unless $table;
74 $table = DBIx::Class::Table->new(
77 result_class => $class,
78 #storage => $class->storage,
80 if ($class->can('table_instance')) {
81 $table->{_columns} = { %{$class->table_instance->{_columns}||{}} };
84 $class->mk_classdata('table_instance' => $table);
89 $class->find_or_create({ key => $val, ... });
91 Searches for a record matching the search condition; if it doesn't find one,
92 creates one and returns that instead.
98 my $hash = ref $_[0] eq "HASH" ? shift: {@_};
99 my $exists = $class->find($hash);
100 return defined($exists) ? $exists : $class->create($hash);
105 if ($obj->has_column($col)) { ... }
107 Returns 1 if the class has a column of this name, 0 otherwise.
112 my ($self, $column) = @_;
113 return $self->table_instance->has_column($column);
118 my $info = $obj->column_info($col);
120 Returns the column metadata hashref for a column.
125 my ($self, $column) = @_;
126 return $self->table_instance->column_info($column);
131 my @column_names = $obj->columns;
136 return shift->table_instance->columns(@_);
143 Matt S. Trout <mst@shadowcatsystems.co.uk>
147 You may distribute this code under the same terms as Perl itself.