use warnings;
use base qw/DBIx::Class::ResultSourceProxy/;
+
use DBIx::Class::ResultSource::Table;
+use Scalar::Util 'blessed';
+use namespace::clean;
+
+__PACKAGE__->mk_classaccessor(table_class => 'DBIx::Class::ResultSource::Table');
+
+# FIXME: Doesn't actually do anything yet!
+__PACKAGE__->mk_group_accessors( inherited => 'table_alias' );
-__PACKAGE__->mk_classdata('table_alias'); # FIXME: Doesn't actually do anything yet!
+sub _init_result_source_instance {
+ my $class = shift;
-__PACKAGE__->mk_classdata('table_class' => 'DBIx::Class::ResultSource::Table');
+ $class->mk_group_accessors( inherited => 'result_source_instance' )
+ unless $class->can('result_source_instance');
-=head1 NAME
+ my $table = $class->result_source_instance;
+ return $table
+ if $table and $table->result_class eq $class;
-DBIx::Class::ResultSourceProxy::Table - provides a classdata table object and method proxies
+ my $table_class = $class->table_class;
+ $class->ensure_class_loaded($table_class);
+
+ if( $table ) {
+ $table = $table_class->new({
+ %$table,
+ result_class => $class,
+ source_name => undef,
+ schema => undef
+ });
+ }
+ else {
+ $table = $table_class->new({
+ name => undef,
+ result_class => $class,
+ source_name => undef,
+ });
+ }
+
+ $class->result_source_instance($table);
+
+ return $table;
+}
+
+=head1 NAME
+
+DBIx::Class::ResultSourceProxy::Table - provides a classdata table
+object and method proxies
=head1 SYNOPSIS
- __PACKAGE__->table('foo');
- __PACKAGE__->add_columns(qw/id bar baz/);
- __PACKAGE__->set_primary_key('id');
+ __PACKAGE__->table('cd');
+ __PACKAGE__->add_columns(qw/cdid artist title year/);
+ __PACKAGE__->set_primary_key('cdid');
=head1 METHODS
=head2 add_columns
- __PACKAGE__->add_columns(qw/col1 col2 col3/);
+ __PACKAGE__->add_columns(qw/cdid artist title year/);
Adds columns to the current class and creates accessors for them.
=head2 table
__PACKAGE__->table('tbl_name');
-
+
Gets or sets the table name.
=cut
sub table {
my ($class, $table) = @_;
return $class->result_source_instance->name unless $table;
- unless (ref $table) {
- $table = $class->table_class->new(
- {
+
+ unless (blessed $table && $table->isa($class->table_class)) {
+
+ my $table_class = $class->table_class;
+ $class->ensure_class_loaded($table_class);
+
+ $table = $table_class->new({
+ $class->can('result_source_instance')
+ ? %{$class->result_source_instance||{}}
+ : ()
+ ,
name => $table,
result_class => $class,
- });
- if ($class->can('result_source_instance')) {
- $table->{_columns} = { %{$class->result_source_instance->{_columns}||{}} };
- $table->{_ordered_columns} =
- [ @{$class->result_source_instance->{_ordered_columns}||[]} ];
- }
- }
- $class->mk_classdata('result_source_instance' => $table);
- if ($class->can('schema_instance')) {
- $class =~ m/([^:]+)$/;
- $class->schema_instance->register_class($class, $class);
+ });
}
+
+ $class->mk_group_accessors(inherited => 'result_source_instance')
+ unless $class->can('result_source_instance');
+
+ $class->result_source_instance($table);
+
+ return $class->result_source_instance->name;
}
-=head2 has_column
-
- if ($obj->has_column($col)) { ... }
-
-Returns 1 if the class has a column of this name, 0 otherwise.
-
-=cut
-
-=head2 column_info
-
- my $info = $obj->column_info($col);
-
-Returns the column metadata hashref for a column.
-
-=cut
+=head2 table_class
-=head2 columns
+ __PACKAGE__->table_class('DBIx::Class::ResultSource::Table');
- my @column_names = $obj->columns;
-
-=cut
+Gets or sets the table class used for construction and validation.
-1;
+=head2 has_column
+
+ if ($obj->has_column($col)) { ... }
+
+Returns 1 if the class has a column of this name, 0 otherwise.
+
+=head2 column_info
-=head1 AUTHORS
+ my $info = $obj->column_info($col);
-Matt S. Trout <mst@shadowcatsystems.co.uk>
+Returns the column metadata hashref for a column. For a description of
+the various types of column data in this hashref, see
+L<DBIx::Class::ResultSource/add_column>
-=head1 LICENSE
+=head2 columns
+
+ my @column_names = $obj->columns;
+
+=head1 FURTHER QUESTIONS?
+
+Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
-You may distribute this code under the same terms as Perl itself.
+=head1 COPYRIGHT AND LICENSE
+
+This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
+by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
+redistribute it and/or modify it under the same terms as the
+L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.
=cut
+1;
+
+