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