[Bast-commits] r6456 - in DBIx-Class/0.08/trunk: lib/DBIx/Class t
t/lib/DBICNSTest t/lib/DBICNSTest/Bogus
ribasushi at dev.catalyst.perl.org
ribasushi at dev.catalyst.perl.org
Sat May 30 05:40:24 GMT 2009
Author: ribasushi
Date: 2009-05-30 05:40:24 +0000 (Sat, 30 May 2009)
New Revision: 6456
Added:
DBIx-Class/0.08/trunk/t/39load_namespaces_exception.t
DBIx-Class/0.08/trunk/t/lib/DBICNSTest/Bogus/
DBIx-Class/0.08/trunk/t/lib/DBICNSTest/Bogus/Bigos.pm
Removed:
DBIx-Class/0.08/trunk/t/lib/DBICNSTest/Bogus/B.pm
Modified:
DBIx-Class/0.08/trunk/lib/DBIx/Class/Schema.pm
DBIx-Class/0.08/trunk/t/lib/DBICNSTest/Bogus/A.pm
Log:
Patch + test for more informative exceptions on load_namespace a non-rs class
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Schema.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Schema.pm 2009-05-30 01:34:36 UTC (rev 6455)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Schema.pm 2009-05-30 05:40:24 UTC (rev 6456)
@@ -173,8 +173,8 @@
}
# 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) = @_;
@@ -190,6 +190,22 @@
@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) = @_;
@@ -231,7 +247,7 @@
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) {
@@ -241,10 +257,10 @@
}
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 ]);
}
Copied: DBIx-Class/0.08/trunk/t/39load_namespaces_exception.t (from rev 6400, DBIx-Class/0.08/trunk/t/39load_namespaces_2.t)
===================================================================
--- DBIx-Class/0.08/trunk/t/39load_namespaces_exception.t (rev 0)
+++ DBIx-Class/0.08/trunk/t/39load_namespaces_exception.t 2009-05-30 05:40:24 UTC (rev 6456)
@@ -0,0 +1,21 @@
+#!/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');
Copied: DBIx-Class/0.08/trunk/t/lib/DBICNSTest/Bogus (from rev 6400, DBIx-Class/0.08/trunk/t/lib/DBICNSTest/Result)
Modified: DBIx-Class/0.08/trunk/t/lib/DBICNSTest/Bogus/A.pm
===================================================================
--- DBIx-Class/0.08/trunk/t/lib/DBICNSTest/Result/A.pm 2009-05-24 13:07:45 UTC (rev 6400)
+++ DBIx-Class/0.08/trunk/t/lib/DBICNSTest/Bogus/A.pm 2009-05-30 05:40:24 UTC (rev 6456)
@@ -1,4 +1,4 @@
-package DBICNSTest::Result::A;
+package DBICNSTest::Bogus::A;
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/PK::Auto Core/);
__PACKAGE__->table('a');
Deleted: DBIx-Class/0.08/trunk/t/lib/DBICNSTest/Bogus/B.pm
===================================================================
--- DBIx-Class/0.08/trunk/t/lib/DBICNSTest/Result/B.pm 2009-05-24 13:07:45 UTC (rev 6400)
+++ DBIx-Class/0.08/trunk/t/lib/DBICNSTest/Bogus/B.pm 2009-05-30 05:40:24 UTC (rev 6456)
@@ -1,6 +0,0 @@
-package DBICNSTest::Result::B;
-use base qw/DBIx::Class/;
-__PACKAGE__->load_components(qw/PK::Auto Core/);
-__PACKAGE__->table('b');
-__PACKAGE__->add_columns('b');
-1;
Added: DBIx-Class/0.08/trunk/t/lib/DBICNSTest/Bogus/Bigos.pm
===================================================================
--- DBIx-Class/0.08/trunk/t/lib/DBICNSTest/Bogus/Bigos.pm (rev 0)
+++ DBIx-Class/0.08/trunk/t/lib/DBICNSTest/Bogus/Bigos.pm 2009-05-30 05:40:24 UTC (rev 6456)
@@ -0,0 +1,3 @@
+package DBICNSTest::Bogus::Bigos;
+
+1;
More information about the Bast-commits
mailing list