fix ResultSourceProxy::Table for inherited classes (needs testing)
[dbsrgits/DBIx-Class-Historic.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 use DBIx::Class::ResultSource::Table;
8
9 __PACKAGE__->mk_classdata('table_alias'); # FIXME: Doesn't actually do anything yet!
10
11 __PACKAGE__->mk_classdata('table_class' => 'DBIx::Class::ResultSource::Table');
12
13 =head1 NAME 
14
15 DBIx::Class::ResultSourceProxy::Table - 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 =head2 add_columns
26
27   __PACKAGE__->add_columns(qw/col1 col2 col3/);
28
29 Adds columns to the current class and creates accessors for them.
30
31 =cut
32
33 =head2 table
34
35   __PACKAGE__->table('tbl_name');
36   
37 Gets or sets the table name.
38
39 =cut
40
41 sub table {
42   my ($class, $table) = @_;
43   return $class->result_source_instance->name unless $table;
44   unless (ref $table) {
45     $table = $class->table_class->new({
46         $class->can('result_source_instance') ? %{$class->result_source_instance} : (),
47         name => $table,
48         result_class => $class,
49     });
50   }
51   $class->mk_classdata('result_source_instance' => $table);
52   if ($class->can('schema_instance')) {
53     $class =~ m/([^:]+)$/;
54     $class->schema_instance->register_class($class, $class);
55   }
56 }
57
58 =head2 has_column                                                                
59                                                                                 
60   if ($obj->has_column($col)) { ... }                                           
61                                                                                 
62 Returns 1 if the class has a column of this name, 0 otherwise.                  
63                                                                                 
64 =cut                                                                            
65
66 =head2 column_info                                                               
67                                                                                 
68   my $info = $obj->column_info($col);                                           
69                                                                                 
70 Returns the column metadata hashref for a column.
71                                                                                 
72 =cut                                                                            
73
74 =head2 columns
75
76   my @column_names = $obj->columns;                                             
77                                                                                 
78 =cut                                                                            
79
80 1;
81
82 =head1 AUTHORS
83
84 Matt S. Trout <mst@shadowcatsystems.co.uk>
85
86 =head1 LICENSE
87
88 You may distribute this code under the same terms as Perl itself.
89
90 =cut
91