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