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