Clarify licensing, ensure footers are consistent throughout the project
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / ResultSourceProxy / Table.pm
index 474c330..647a408 100644 (file)
@@ -6,6 +6,8 @@ use warnings;
 use base qw/DBIx::Class::ResultSourceProxy/;
 
 use DBIx::Class::ResultSource::Table;
+use Scalar::Util 'blessed';
+use namespace::clean;
 
 __PACKAGE__->mk_classdata(table_class => 'DBIx::Class::ResultSource::Table');
 
@@ -22,8 +24,11 @@ sub _init_result_source_instance {
     my $class_has_table_instance = ($table and $table->result_class eq $class);
     return $table if $class_has_table_instance;
 
+    my $table_class = $class->table_class;
+    $class->ensure_class_loaded($table_class);
+
     if( $table ) {
-        $table = $class->table_class->new({
+        $table = $table_class->new({
             %$table,
             result_class => $class,
             source_name => undef,
@@ -31,7 +36,7 @@ sub _init_result_source_instance {
         });
     }
     else {
-        $table = $class->table_class->new({
+        $table = $table_class->new({
             name            => undef,
             result_class    => $class,
             source_name     => undef,
@@ -40,11 +45,6 @@ sub _init_result_source_instance {
 
     $class->result_source_instance($table);
 
-    if ($class->can('schema_instance')) {
-        $class =~ m/([^:]+)$/;
-        $class->schema_instance->register_class($class, $class);
-    }
-
     return $table;
 }
 
@@ -72,7 +72,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
@@ -80,13 +80,19 @@ Gets or sets the table name.
 sub table {
   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,
     });
   }
 
@@ -95,20 +101,21 @@ sub table {
 
   $class->result_source_instance($table);
 
-  if ($class->can('schema_instance')) {
-    $class =~ m/([^:]+)$/;
-    $class->schema_instance->register_class($class, $class);
-  }
+  return $class->result_source_instance->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);
@@ -117,23 +124,23 @@ 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>
 
-=cut
-
 =head2 columns
 
   my @column_names = $obj->columns;
 
-=cut
+=head1 FURTHER QUESTIONS?
 
-1;
+Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
 
-=head1 AUTHORS
+=head1 COPYRIGHT AND LICENSE
 
-Matt S. Trout <mst@shadowcatsystems.co.uk>
+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>.
 
-=head1 LICENSE
+=cut
 
-You may distribute this code under the same terms as Perl itself.
+1;
 
-=cut