Silence cdbi tests like everything else
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / ResultSourceProxy / Table.pm
CommitLineData
80c90f5d 1package DBIx::Class::ResultSourceProxy::Table;
cda04c3a 2
3use strict;
4use warnings;
5
80c90f5d 6use base qw/DBIx::Class::ResultSourceProxy/;
cda04c3a 7
3e110410 8use DBIx::Class::ResultSource::Table;
9
10__PACKAGE__->mk_classdata(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
e60dc79f 15sub _init_result_source_instance {
16 my $class = shift;
17
18 $class->mk_classdata('result_source_instance')
19 unless $class->can('result_source_instance');
20
21 my $table = $class->result_source_instance;
22 my $class_has_table_instance = ($table and $table->result_class eq $class);
23 return $table if $class_has_table_instance;
24
25 if( $table ) {
26 $table = $class->table_class->new({
27 %$table,
28 result_class => $class,
29 source_name => undef,
30 schema => undef
31 });
32 }
33 else {
34 $table = $class->table_class->new({
35 name => undef,
36 result_class => $class,
37 source_name => undef,
38 });
39 }
40
41 $class->result_source_instance($table);
42
dec1bfe0 43 if ($class->can('schema_instance') && $class->schema_instance) {
e60dc79f 44 $class =~ m/([^:]+)$/;
45 $class->schema_instance->register_class($class, $class);
46 }
47
48 return $table;
49}
50
75d07914 51=head1 NAME
cda04c3a 52
24d67825 53DBIx::Class::ResultSourceProxy::Table - provides a classdata table
54object and method proxies
cda04c3a 55
56=head1 SYNOPSIS
57
24d67825 58 __PACKAGE__->table('cd');
59 __PACKAGE__->add_columns(qw/cdid artist title year/);
60 __PACKAGE__->set_primary_key('cdid');
cda04c3a 61
62=head1 METHODS
63
cda04c3a 64=head2 add_columns
65
24d67825 66 __PACKAGE__->add_columns(qw/cdid artist title year/);
cda04c3a 67
68Adds columns to the current class and creates accessors for them.
69
70=cut
71
cda04c3a 72=head2 table
73
74 __PACKAGE__->table('tbl_name');
75
76Gets or sets the table name.
77
78=cut
79
80sub table {
81 my ($class, $table) = @_;
b98e75f6 82 return $class->result_source_instance->name unless $table;
cda04c3a 83 unless (ref $table) {
5a879106 84 $table = $class->table_class->new({
24d67825 85 $class->can('result_source_instance') ?
e60dc79f 86 %{$class->result_source_instance||{}} : (),
cda04c3a 87 name => $table,
88 result_class => $class,
b1fb2c94 89 source_name => undef,
5a879106 90 });
cda04c3a 91 }
e87bedbe 92
93 $class->mk_classdata('result_source_instance')
94 unless $class->can('result_source_instance');
95
96 $class->result_source_instance($table);
97
7fb16f1a 98 if ($class->can('schema_instance')) {
99 $class =~ m/([^:]+)$/;
100 $class->schema_instance->register_class($class, $class);
101 }
ade8df5b 102 return $class->result_source_instance->name;
cda04c3a 103}
104
988bf309 105=head2 has_column
106
107 if ($obj->has_column($col)) { ... }
108
109Returns 1 if the class has a column of this name, 0 otherwise.
110
111=cut
112
113=head2 column_info
114
115 my $info = $obj->column_info($col);
116
117Returns the column metadata hashref for a column. For a description of
118the various types of column data in this hashref, see
75d07914 119L<DBIx::Class::ResultSource/add_column>
988bf309 120
121=cut
cda04c3a 122
d7156e50 123=head2 columns
124
988bf309 125 my @column_names = $obj->columns;
126
127=cut
cda04c3a 128
cda04c3a 1291;
130
131=head1 AUTHORS
132
133Matt S. Trout <mst@shadowcatsystems.co.uk>
134
135=head1 LICENSE
136
137You may distribute this code under the same terms as Perl itself.
138
139=cut
140