X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FResultSourceProxy%2FTable.pm;h=a983ce19d350b1614bccd7bee1a7f355eaa1c79f;hb=d4daee7b54e38e4b3d3d0a77759bddc1a4ede6e5;hp=6717f82270266a433c7b77a5f6f2bd4a748e0747;hpb=fc9690056f17278f057021803b1124ebbd5a0d2d;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/ResultSourceProxy/Table.pm b/lib/DBIx/Class/ResultSourceProxy/Table.pm index 6717f82..a983ce1 100644 --- a/lib/DBIx/Class/ResultSourceProxy/Table.pm +++ b/lib/DBIx/Class/ResultSourceProxy/Table.pm @@ -4,28 +4,61 @@ use strict; use warnings; use base qw/DBIx::Class::ResultSourceProxy/; -__PACKAGE__->load_components(qw/AccessorGroup/); -__PACKAGE__->mk_group_accessors('component_class' => 'table_class'); -__PACKAGE__->table_class('DBIx::Class::ResultSource::Table'); +use DBIx::Class::ResultSource::Table; -__PACKAGE__->mk_classdata('table_alias'); # FIXME: Doesn't actually do anything yet! +__PACKAGE__->mk_classdata(table_class => 'DBIx::Class::ResultSource::Table'); -=head1 NAME +__PACKAGE__->mk_classdata('table_alias'); # FIXME: Doesn't actually do + # anything yet! -DBIx::Class::ResultSourceProxy::Table - provides a classdata table object and method proxies +sub _init_result_source_instance { + my $class = shift; + + $class->mk_classdata('result_source_instance') + unless $class->can('result_source_instance'); + + my $table = $class->result_source_instance; + my $class_has_table_instance = ($table and $table->result_class eq $class); + return $table if $class_has_table_instance; + + if( $table ) { + $table = $class->table_class->new({ + %$table, + result_class => $class, + source_name => undef, + schema => undef + }); + } + else { + $table = $class->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. @@ -34,7 +67,7 @@ Adds columns to the current class and creates accessors for them. =head2 table __PACKAGE__->table('tbl_name'); - + Gets or sets the table name. =cut @@ -44,39 +77,45 @@ sub table { return $class->result_source_instance->name unless $table; unless (ref $table) { $table = $class->table_class->new({ - $class->can('result_source_instance') ? %{$class->result_source_instance} : (), + $class->can('result_source_instance') ? + %{$class->result_source_instance||{}} : (), name => $table, result_class => $class, + source_name => undef, }); } - $class->mk_classdata('result_source_instance' => $table); - if ($class->can('schema_instance')) { - $class =~ m/([^:]+)$/; - $class->schema_instance->register_class($class, $class); - } + + $class->mk_classdata('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 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. For a description of +the various types of column data in this hashref, see +L + +=cut =head2 columns - my @column_names = $obj->columns; - -=cut + my @column_names = $obj->columns; + +=cut 1;