[Bast-commits] r4749 - in DBIx-Class/0.08/trunk: lib/DBIx/Class t
t/lib/DBICTest/Schema
castaway at dev.catalyst.perl.org
castaway at dev.catalyst.perl.org
Tue Aug 12 14:14:10 BST 2008
Author: castaway
Date: 2008-08-12 14:14:10 +0100 (Tue, 12 Aug 2008)
New Revision: 4749
Added:
DBIx-Class/0.08/trunk/t/102load_classes.t
DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/NoSuchClass.pm
Modified:
DBIx-Class/0.08/trunk/lib/DBIx/Class/Schema.pm
Log:
Add saner warning when non-source classes encountered in schema subdir by load_classes.
Also skip the broken ones.
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Schema.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Schema.pm 2008-08-12 10:35:00 UTC (rev 4748)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Schema.pm 2008-08-12 13:14:10 UTC (rev 4749)
@@ -328,8 +328,13 @@
}
$class->ensure_class_loaded($comp_class);
- $comp = $comp_class->source_name || $comp;
-# $DB::single = 1;
+ my $snsub = $comp_class->can('source_name');
+ if(! $snsub ) {
+ warn "Failed to load $comp_class. Can't find source_name method. Is $comp_class really a full DBIC result class? Fix it, move it elsewhere, or make your load_classes call more specific.";
+ next;
+ }
+ $comp = $snsub->($comp_class) || $comp;
+
push(@to_register, [ $comp, $comp_class ]);
}
}
Added: DBIx-Class/0.08/trunk/t/102load_classes.t
===================================================================
--- DBIx-Class/0.08/trunk/t/102load_classes.t (rev 0)
+++ DBIx-Class/0.08/trunk/t/102load_classes.t 2008-08-12 13:14:10 UTC (rev 4749)
@@ -0,0 +1,25 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Test::More;
+
+unshift(@INC, './t/lib');
+
+plan tests => 4;
+
+my $warnings;
+eval {
+ local $SIG{__WARN__} = sub { $warnings .= shift };
+ package DBICTest::Schema;
+ use base qw/DBIx::Class::Schema/;
+ __PACKAGE__->load_classes;
+};
+ok(!$@, 'Loaded all loadable classes') or diag $@;
+like($warnings, qr/Failed to load DBICTest::Schema::NoSuchClass. Can't find source_name method. Is DBICTest::Schema::NoSuchClass really a full DBIC result class?/, 'Warned about broken result class');
+
+my $source_a = DBICTest::Schema->source('Artist');
+isa_ok($source_a, 'DBIx::Class::ResultSource::Table');
+my $rset_a = DBICTest::Schema->resultset('Artist');
+isa_ok($rset_a, 'DBIx::Class::ResultSet');
+
Added: DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/NoSuchClass.pm
===================================================================
--- DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/NoSuchClass.pm (rev 0)
+++ DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/NoSuchClass.pm 2008-08-12 13:14:10 UTC (rev 4749)
@@ -0,0 +1,6 @@
+package DBICTest::Schema::NoSuchClass;
+
+## This is purposefully not a real DBIC class
+## Used in t/102load_classes.t
+
+1;
More information about the Bast-commits
mailing list