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 | |
24d67825 | 12 | __PACKAGE__->mk_classdata('table_alias'); # FIXME: Doesn't actually do |
75d07914 | 13 | # anything yet! |
cda04c3a | 14 | |
75d07914 | 15 | =head1 NAME |
cda04c3a | 16 | |
24d67825 | 17 | DBIx::Class::ResultSourceProxy::Table - provides a classdata table |
18 | object and method proxies | |
cda04c3a | 19 | |
20 | =head1 SYNOPSIS | |
21 | ||
24d67825 | 22 | __PACKAGE__->table('cd'); |
23 | __PACKAGE__->add_columns(qw/cdid artist title year/); | |
24 | __PACKAGE__->set_primary_key('cdid'); | |
cda04c3a | 25 | |
26 | =head1 METHODS | |
27 | ||
cda04c3a | 28 | =head2 add_columns |
29 | ||
24d67825 | 30 | __PACKAGE__->add_columns(qw/cdid artist title year/); |
cda04c3a | 31 | |
32 | Adds columns to the current class and creates accessors for them. | |
33 | ||
34 | =cut | |
35 | ||
cda04c3a | 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) = @_; | |
b98e75f6 | 46 | return $class->result_source_instance->name unless $table; |
cda04c3a | 47 | unless (ref $table) { |
5a879106 | 48 | $table = $class->table_class->new({ |
24d67825 | 49 | $class->can('result_source_instance') ? |
75d07914 | 50 | %{$class->result_source_instance} : (), |
cda04c3a | 51 | name => $table, |
52 | result_class => $class, | |
b1fb2c94 | 53 | source_name => undef, |
5a879106 | 54 | }); |
cda04c3a | 55 | } |
b98e75f6 | 56 | $class->mk_classdata('result_source_instance' => $table); |
7fb16f1a | 57 | if ($class->can('schema_instance')) { |
58 | $class =~ m/([^:]+)$/; | |
59 | $class->schema_instance->register_class($class, $class); | |
60 | } | |
cda04c3a | 61 | } |
62 | ||
988bf309 | 63 | =head2 has_column |
64 | ||
65 | if ($obj->has_column($col)) { ... } | |
66 | ||
67 | Returns 1 if the class has a column of this name, 0 otherwise. | |
68 | ||
69 | =cut | |
70 | ||
71 | =head2 column_info | |
72 | ||
73 | my $info = $obj->column_info($col); | |
74 | ||
75 | Returns the column metadata hashref for a column. For a description of | |
76 | the various types of column data in this hashref, see | |
75d07914 | 77 | L<DBIx::Class::ResultSource/add_column> |
988bf309 | 78 | |
79 | =cut | |
cda04c3a | 80 | |
d7156e50 | 81 | =head2 columns |
82 | ||
988bf309 | 83 | my @column_names = $obj->columns; |
84 | ||
85 | =cut | |
cda04c3a | 86 | |
cda04c3a | 87 | 1; |
88 | ||
89 | =head1 AUTHORS | |
90 | ||
91 | Matt S. Trout <mst@shadowcatsystems.co.uk> | |
92 | ||
93 | =head1 LICENSE | |
94 | ||
95 | You may distribute this code under the same terms as Perl itself. | |
96 | ||
97 | =cut | |
98 |