result_source is now AN ACCESSOR. w00000
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / TableInstance.pm
CommitLineData
cda04c3a 1package DBIx::Class::TableInstance;
2
3use strict;
4use warnings;
5
b98e75f6 6use base qw/DBIx::Class::ResultSourceInstance/;
cda04c3a 7use DBIx::Class::Table;
8
9__PACKAGE__->mk_classdata('table_alias'); # FIXME: Doesn't actually do anything yet!
10
f6858c33 11__PACKAGE__->mk_classdata('table_class' => 'DBIx::Class::Table');
cda04c3a 12
cda04c3a 13=head1 NAME
14
15DBIx::Class::TableInstance - provides a classdata table object and method proxies
16
17=head1 SYNOPSIS
18
19 __PACKAGE__->table('foo');
20 __PACKAGE__->add_columns(qw/id bar baz/);
21 __PACKAGE__->set_primary_key('id');
22
23=head1 METHODS
24
25=cut
26
27sub _mk_column_accessors {
28 my ($class, @cols) = @_;
29 $class->mk_group_accessors('column' => @cols);
30}
31
32=head2 add_columns
33
34 __PACKAGE__->add_columns(qw/col1 col2 col3/);
35
36Adds columns to the current class and creates accessors for them.
37
38=cut
39
cda04c3a 40=head2 table
41
42 __PACKAGE__->table('tbl_name');
43
44Gets or sets the table name.
45
46=cut
47
48sub table {
49 my ($class, $table) = @_;
b98e75f6 50 return $class->result_source_instance->name unless $table;
cda04c3a 51 unless (ref $table) {
f6858c33 52 $table = $class->table_class->new(
cda04c3a 53 {
54 name => $table,
55 result_class => $class,
cda04c3a 56 });
b98e75f6 57 if ($class->can('result_source_instance')) {
58 $table->{_columns} = { %{$class->result_source_instance->{_columns}||{}} };
ec77fadc 59 }
cda04c3a 60 }
b98e75f6 61 $class->mk_classdata('result_source_instance' => $table);
7fb16f1a 62 if ($class->can('schema_instance')) {
63 $class =~ m/([^:]+)$/;
64 $class->schema_instance->register_class($class, $class);
65 }
cda04c3a 66}
67
cda04c3a 68=head2 has_column
69
70 if ($obj->has_column($col)) { ... }
71
72Returns 1 if the class has a column of this name, 0 otherwise.
73
74=cut
75
cda04c3a 76=head2 column_info
77
78 my $info = $obj->column_info($col);
79
80Returns the column metadata hashref for a column.
81
82=cut
83
d7156e50 84=head2 columns
85
cda04c3a 86 my @column_names = $obj->columns;
87
88=cut
89
cda04c3a 901;
91
92=head1 AUTHORS
93
94Matt S. Trout <mst@shadowcatsystems.co.uk>
95
96=head1 LICENSE
97
98You may distribute this code under the same terms as Perl itself.
99
100=cut
101