A couple of typos, and general whitespace cleanup (ick)
[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/;
cda04c3a 7
3e110410 8use DBIx::Class::ResultSource::Table;
9
10__PACKAGE__->mk_classdata(table_class => 'DBIx::Class::ResultSource::Table');
cda04c3a 11
24d67825 12__PACKAGE__->mk_classdata('table_alias'); # FIXME: Doesn't actually do
75d07914 13 # anything yet!
cda04c3a 14
e60dc79f 15sub _init_result_source_instance {
16 my $class = shift;
17
18 $class->mk_classdata('result_source_instance')
19 unless $class->can('result_source_instance');
20
21 my $table = $class->result_source_instance;
22 my $class_has_table_instance = ($table and $table->result_class eq $class);
23 return $table if $class_has_table_instance;
24
25 if( $table ) {
26 $table = $class->table_class->new({
27 %$table,
28 result_class => $class,
29 source_name => undef,
30 schema => undef
31 });
32 }
33 else {
34 $table = $class->table_class->new({
35 name => undef,
36 result_class => $class,
37 source_name => undef,
38 });
39 }
40
41 $class->result_source_instance($table);
42
e60dc79f 43 return $table;
44}
45
75d07914 46=head1 NAME
cda04c3a 47
24d67825 48DBIx::Class::ResultSourceProxy::Table - provides a classdata table
49object and method proxies
cda04c3a 50
51=head1 SYNOPSIS
52
24d67825 53 __PACKAGE__->table('cd');
54 __PACKAGE__->add_columns(qw/cdid artist title year/);
55 __PACKAGE__->set_primary_key('cdid');
cda04c3a 56
57=head1 METHODS
58
cda04c3a 59=head2 add_columns
60
24d67825 61 __PACKAGE__->add_columns(qw/cdid artist title year/);
cda04c3a 62
63Adds columns to the current class and creates accessors for them.
64
65=cut
66
cda04c3a 67=head2 table
68
69 __PACKAGE__->table('tbl_name');
d4daee7b 70
cda04c3a 71Gets or sets the table name.
72
73=cut
74
75sub table {
76 my ($class, $table) = @_;
b98e75f6 77 return $class->result_source_instance->name unless $table;
cda04c3a 78 unless (ref $table) {
5a879106 79 $table = $class->table_class->new({
24d67825 80 $class->can('result_source_instance') ?
e60dc79f 81 %{$class->result_source_instance||{}} : (),
cda04c3a 82 name => $table,
83 result_class => $class,
b1fb2c94 84 source_name => undef,
5a879106 85 });
cda04c3a 86 }
e87bedbe 87
88 $class->mk_classdata('result_source_instance')
89 unless $class->can('result_source_instance');
90
91 $class->result_source_instance($table);
92
ade8df5b 93 return $class->result_source_instance->name;
cda04c3a 94}
95
988bf309 96=head2 has_column
97
98 if ($obj->has_column($col)) { ... }
99
100Returns 1 if the class has a column of this name, 0 otherwise.
101
102=cut
103
104=head2 column_info
105
106 my $info = $obj->column_info($col);
107
108Returns the column metadata hashref for a column. For a description of
109the various types of column data in this hashref, see
75d07914 110L<DBIx::Class::ResultSource/add_column>
988bf309 111
112=cut
cda04c3a 113
d7156e50 114=head2 columns
115
988bf309 116 my @column_names = $obj->columns;
117
118=cut
cda04c3a 119
cda04c3a 1201;
121
122=head1 AUTHORS
123
124Matt S. Trout <mst@shadowcatsystems.co.uk>
125
126=head1 LICENSE
127
128You may distribute this code under the same terms as Perl itself.
129
130=cut
131