From: Peter Rabbitson Date: Wed, 5 Aug 2009 13:41:28 +0000 (+0000) Subject: Dynamically load necessary table classes X-Git-Tag: v0.08109~40 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=846e17a679e91078d7c7fd3a2f0ca80749dc5d34;p=dbsrgits%2FDBIx-Class.git Dynamically load necessary table classes --- diff --git a/lib/DBIx/Class/Manual/Cookbook.pod b/lib/DBIx/Class/Manual/Cookbook.pod index d1e559c..8728eb5 100644 --- a/lib/DBIx/Class/Manual/Cookbook.pod +++ b/lib/DBIx/Class/Manual/Cookbook.pod @@ -111,8 +111,6 @@ L for your query. use warnings; use base qw/DBIx::Class/; - use DBIx::Class::ResultSource::View; - __PACKAGE__->load_components('Core'); __PACKAGE__->table_class('DBIx::Class::ResultSource::View'); diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index c5f157f..1b93f4e 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -40,8 +40,6 @@ DBIx::Class::ResultSource - Result source object # Create a query (view) based result source, in a result class package MyDB::Schema::Result::Year2000CDs; - use DBIx::Class::ResultSource::View; - __PACKAGE__->load_components('Core'); __PACKAGE__->table_class('DBIx::Class::ResultSource::View'); diff --git a/lib/DBIx/Class/ResultSource/View.pm b/lib/DBIx/Class/ResultSource/View.pm index ea37971..d992c71 100644 --- a/lib/DBIx/Class/ResultSource/View.pm +++ b/lib/DBIx/Class/ResultSource/View.pm @@ -20,7 +20,6 @@ DBIx::Class::ResultSource::View - ResultSource object representing a view package MyDB::Schema::Result::Year2000CDs; use base qw/DBIx::Class/; - use DBIx::Class::ResultSource::View; __PACKAGE__->load_components('Core'); __PACKAGE__->table_class('DBIx::Class::ResultSource::View'); diff --git a/lib/DBIx/Class/ResultSourceProxy/Table.pm b/lib/DBIx/Class/ResultSourceProxy/Table.pm index a983ce1..929c300 100644 --- a/lib/DBIx/Class/ResultSourceProxy/Table.pm +++ b/lib/DBIx/Class/ResultSourceProxy/Table.pm @@ -5,8 +5,6 @@ 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 @@ -22,8 +20,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 +32,7 @@ sub _init_result_source_instance { }); } else { - $table = $class->table_class->new({ + $table = $table_class->new({ name => undef, result_class => $class, source_name => undef, @@ -76,7 +77,11 @@ sub table { my ($class, $table) = @_; return $class->result_source_instance->name unless $table; unless (ref $table) { - $table = $class->table_class->new({ + + 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, diff --git a/t/lib/DBICTest/Schema/Year1999CDs.pm b/t/lib/DBICTest/Schema/Year1999CDs.pm index 4aea122..ee1c9ec 100644 --- a/t/lib/DBICTest/Schema/Year1999CDs.pm +++ b/t/lib/DBICTest/Schema/Year1999CDs.pm @@ -3,7 +3,6 @@ package # hide from PAUSE ## Used in 104view.t use base qw/DBICTest::BaseResult/; -use DBIx::Class::ResultSource::View; __PACKAGE__->table_class('DBIx::Class::ResultSource::View'); diff --git a/t/lib/DBICTest/Schema/Year2000CDs.pm b/t/lib/DBICTest/Schema/Year2000CDs.pm index ebc4395..7f75f5f 100644 --- a/t/lib/DBICTest/Schema/Year2000CDs.pm +++ b/t/lib/DBICTest/Schema/Year2000CDs.pm @@ -3,7 +3,6 @@ package # hide from PAUSE ## Used in 104view.t use base qw/DBICTest::BaseResult/; -use DBIx::Class::ResultSource::View; __PACKAGE__->table_class('DBIx::Class::ResultSource::View');