[Dbix-class] Patch for better error reporting
Andy Grundman
andy at hybridized.org
Fri Dec 9 19:22:48 CET 2005
This is a partially-working patch for reporting errors when loading
classes referenced in relationships. I'd commit it but it breaks CDBI
compat:
DBIx/Class/CDBICompat/TempColumns.pm did not return a true value
-Andy
-------------- next part --------------
Index: lib/DBIx/Class/Relationship/Base.pm
===================================================================
--- lib/DBIx/Class/Relationship/Base.pm (revision 366)
+++ lib/DBIx/Class/Relationship/Base.pm (working copy)
@@ -43,6 +43,9 @@
die "Can't create relationship without join condition" unless $cond;
$attrs ||= {};
eval "require $f_class;";
+ if ($@) {
+ $class->throw($@) unless $@ =~ /Can't locate/;
+ }
my %rels = %{ $class->_relationships };
$rels{$rel} = { class => $f_class,
cond => $cond,
Index: lib/DBIx/Class/Relationship/BelongsTo.pm
===================================================================
--- lib/DBIx/Class/Relationship/BelongsTo.pm (revision 366)
+++ lib/DBIx/Class/Relationship/BelongsTo.pm (working copy)
@@ -6,6 +6,10 @@
sub belongs_to {
my ($class, $rel, $f_class, $cond, $attrs) = @_;
eval "require $f_class";
+ if ($@) {
+ $class->throw($@) unless $@ =~ /Can't locate/;
+ }
+
my %f_primaries;
$f_primaries{$_} = 1 for eval { $f_class->primary_columns };
my $f_loaded = !$@;
Index: lib/DBIx/Class/Relationship/HasOne.pm
===================================================================
--- lib/DBIx/Class/Relationship/HasOne.pm (revision 366)
+++ lib/DBIx/Class/Relationship/HasOne.pm (working copy)
@@ -14,6 +14,10 @@
sub _has_one {
my ($class, $join_type, $rel, $f_class, $cond, $attrs) = @_;
eval "require $f_class";
+ if ($@) {
+ $class->throw($@) unless $@ =~ /Can't locate/;
+ }
+
unless (ref $cond) {
my ($pri, $too_many) = $class->primary_columns;
$class->throw( "might_have/has_one can only infer join for a single primary key; ${class} has more" )
Index: lib/DBIx/Class/Relationship/HasMany.pm
===================================================================
--- lib/DBIx/Class/Relationship/HasMany.pm (revision 366)
+++ lib/DBIx/Class/Relationship/HasMany.pm (working copy)
@@ -7,6 +7,9 @@
my ($class, $rel, $f_class, $cond, $attrs) = @_;
eval "require $f_class";
+ if ($@) {
+ $class->throw($@) unless $@ =~ /Can't locate/;
+ }
unless (ref $cond) {
my ($pri, $too_many) = $class->primary_columns;
Index: Changes
===================================================================
--- Changes (revision 366)
+++ Changes (working copy)
@@ -2,6 +2,7 @@
0.04001
- Fix so set_inflated_column calls set_column
+ - Allow syntax errors in relationship classes to be reported.
0.04 2005-11-26
- Moved get_simple and set_simple into AccessorGroup
More information about the Dbix-class
mailing list