use DBIx::Class::Storage::DBI;
use DBIx::Class::ClassResolver::PassThrough;
use DBI;
+use Scalar::Util;
unless ($INC{"DBIx/Class/CDBICompat.pm"}) {
warn "IMPORTANT: DBIx::Class::DB is DEPRECATED AND *WILL* BE REMOVED. DO NOT USE.\n";
=cut
sub resultset_instance {
- my $class = ref $_[0] || $_[0];
- my $source = $class->result_source_instance;
+ $_[0]->result_source_instance->resultset
+}
+
+sub result_source_instance {
+ my $class = shift;
+ $class = ref $class || $class;
+
+ __PACKAGE__->mk_classdata(qw/_result_source_instance/)
+ unless __PACKAGE__->can('_result_source_instance');
+
+
+ return $class->_result_source_instance(@_) if @_;
+
+ my $source = $class->_result_source_instance;
+ return {} unless Scalar::Util::blessed($source);
+
if ($source->result_class ne $class) {
- $source = $source->new($source);
- $source->result_class($class);
+ # Remove old source instance so we dont get deep recursion
+ #$DB::single = 1;
+ # Need to set it to a non-undef value so that it doesn't just fallback to
+ # a parent class's _result_source_instance
+ #$class->_result_source_instance({});
+ #$class->table($class);
+ #$source = $class->_result_source_instance;
+
+ $DB::single = 1;
+ $source = $source->new({
+ %$source,
+ source_name => $class,
+ result_class => $class
+ } );
+ $class->_result_source_instance($source);
+ if (my $coderef = $class->can('schema_instance')) {
+ $coderef->($class)->register_class($class, $class);
+ }
}
- return $source->resultset;
+ return $source;
}
=head2 resolve_class
source_name => undef,
});
}
- $class->mk_classdata('result_source_instance' => $table);
+
+ $class->mk_classdata('result_source_instance')
+ unless $class->can('result_source_instance');
+
+ $class->result_source_instance($table);
+
if ($class->can('schema_instance')) {
$class =~ m/([^:]+)$/;
$class->schema_instance->register_class($class, $class);
my $schema = DBICTest->init_schema();
-DBICTest::Schema::CD->add_column('year2');
-$DB::single = 1;
eval { require DateTime };
plan skip_all => "Need DateTime for inflation tests" if $@;
plan tests => 4;
-$DB::single = 1;
-
$schema->class('CD')
#DBICTest::Schema::CD
->inflate_column( 'year',