}
# returns a hash of $shortname => $fullname for every package
-# found in the given namespaces ($shortname is with the $fullname's
-# namespace stripped off)
+# found in the given namespaces ($shortname is with the $fullname's
+# namespace stripped off)
sub _map_namespaces {
my ($class, @namespaces) = @_;
@results_hash;
}
+# returns the result_source_instance for the passed class/object,
+# or dies with an informative message (used by load_namespaces)
+sub _ns_get_rsrc_instance {
+ my $class = shift;
+ my $rs = ref ($_[0]) || $_[0];
+
+ if ($rs->can ('result_source_instance') ) {
+ return $rs->result_source_instance;
+ }
+ else {
+ $class->throw_exception (
+ "Attempt to load_namespaces() class $rs failed - are you sure this is a real Result Class?"
+ );
+ }
+}
+
sub load_namespaces {
my ($class, %args) = @_;
my $result_class = $results{$result};
my $rs_class = delete $resultsets{$result};
- my $rs_set = $result_class->resultset_class;
+ my $rs_set = $class->_ns_get_rsrc_instance ($result_class)->resultset_class;
if($rs_set && $rs_set ne 'DBIx::Class::ResultSet') {
if($rs_class && $rs_class ne $rs_set) {
}
elsif($rs_class ||= $default_resultset_class) {
$class->ensure_class_loaded($rs_class);
- $result_class->resultset_class($rs_class);
+ $class->_ns_get_rsrc_instance ($result_class)->resultset_class($rs_class);
}
- my $source_name = $result_class->source_name || $result;
+ my $source_name = $class->_ns_get_rsrc_instance ($result_class)->source_name || $result;
push(@to_register, [ $source_name, $result_class ]);
}
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Test::More;
+
+use lib qw(t/lib);
+use DBICTest; # do not remove even though it is not used
+
+plan tests => 1;
+
+eval {
+ package DBICNSTest;
+ use base qw/DBIx::Class::Schema/;
+ __PACKAGE__->load_namespaces(
+ result_namespace => 'Bogus',
+ resultset_namespace => 'RSet',
+ );
+};
+
+like ($@, qr/are you sure this is a real Result Class/, 'Clear exception thrown');