X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FResultSourceProxy%2FTable.pm;h=c165f7702416d3b230843ffec09ae7a4d653430b;hb=d46eac43287ebe244e4f622fb77fa2efa16402a9;hp=0816dd7920e56e88920d245edcc4e7c3d6863a70;hpb=3e11041012dc26df94860efefde4340bf927f2af;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/ResultSourceProxy/Table.pm b/lib/DBIx/Class/ResultSourceProxy/Table.pm index 0816dd7..c165f77 100644 --- a/lib/DBIx/Class/ResultSourceProxy/Table.pm +++ b/lib/DBIx/Class/ResultSourceProxy/Table.pm @@ -6,11 +6,47 @@ use warnings; use base qw/DBIx::Class::ResultSourceProxy/; use DBIx::Class::ResultSource::Table; - -__PACKAGE__->mk_classdata(table_class => 'DBIx::Class::ResultSource::Table'); - -__PACKAGE__->mk_classdata('table_alias'); # FIXME: Doesn't actually do - # anything yet! +use Scalar::Util 'blessed'; +use namespace::clean; + +# FIXME - both of these *PROBABLY* need to be 'inherited_ro_instance' type +__PACKAGE__->mk_classaccessor(table_class => 'DBIx::Class::ResultSource::Table'); +# FIXME: Doesn't actually do anything yet! +__PACKAGE__->mk_group_accessors( inherited => 'table_alias' ); + +sub _init_result_source_instance { + my $class = shift; + + $class->mk_group_accessors( inherited => 'result_source_instance' ) + unless $class->can('result_source_instance'); + + # might be pre-made for us courtesy of DBIC::DB::result_source_instance() + my $rsrc = $class->result_source_instance; + + return $rsrc + if $rsrc and $rsrc->result_class eq $class; + + my $table_class = $class->table_class; + $class->ensure_class_loaded($table_class); + + if( $rsrc ) { + $rsrc = $table_class->new({ + %$rsrc, + result_class => $class, + source_name => undef, + schema => undef + }); + } + else { + $rsrc = $table_class->new({ + name => undef, + result_class => $class, + source_name => undef, + }); + } + + $class->result_source_instance($rsrc); +} =head1 NAME @@ -36,38 +72,49 @@ 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 { + return $_[0]->result_source_instance->name unless @_ > 1; + my ($class, $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} : (), + + 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, - 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_group_accessors(inherited => 'result_source_instance') + unless $class->can('result_source_instance'); + + $class->result_source_instance($table)->name; } +=head2 table_class + + __PACKAGE__->table_class('DBIx::Class::ResultSource::Table'); + +Gets or sets the table class used for construction and validation. + =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); @@ -76,23 +123,23 @@ 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 +=head1 FURTHER QUESTIONS? -1; +Check the list of L. -=head1 AUTHORS +=head1 COPYRIGHT AND LICENSE -Matt S. Trout +This module is free software L +by the L. You can +redistribute it and/or modify it under the same terms as the +L. -=head1 LICENSE +=cut -You may distribute this code under the same terms as Perl itself. +1; -=cut