Commit | Line | Data |
80c90f5d |
1 | package DBIx::Class::ResultSourceProxy::Table; |
cda04c3a |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
80c90f5d |
6 | use 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 |
16 | DBIx::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 | |
30 | Adds 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 | |
38 | Gets or sets the table name. |
39 | |
40 | =cut |
41 | |
42 | sub 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 | |
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 |
cda04c3a |
76 | |
d7156e50 |
77 | =head2 columns |
78 | |
988bf309 |
79 | my @column_names = $obj->columns; |
80 | |
81 | =cut |
cda04c3a |
82 | |
cda04c3a |
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 | |