From: Matt S Trout Date: Fri, 9 Dec 2005 19:40:00 +0000 (+0000) Subject: Merged patched from andyg to throw useful errors during relationship loading X-Git-Tag: v0.05005~152 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=55de06f116aadb02326d4613a4db7117941e5350;p=dbsrgits%2FDBIx-Class.git Merged patched from andyg to throw useful errors during relationship loading --- diff --git a/Changes b/Changes index 108399f..dc95be0 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,7 @@ Revision history for DBIx::Class 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 diff --git a/lib/DBIx/Class/Relationship/Base.pm b/lib/DBIx/Class/Relationship/Base.pm index b1ca7fb..4590985 100644 --- a/lib/DBIx/Class/Relationship/Base.pm +++ b/lib/DBIx/Class/Relationship/Base.pm @@ -43,6 +43,9 @@ sub add_relationship { 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, diff --git a/lib/DBIx/Class/Relationship/BelongsTo.pm b/lib/DBIx/Class/Relationship/BelongsTo.pm index aca69aa..7435d7b 100644 --- a/lib/DBIx/Class/Relationship/BelongsTo.pm +++ b/lib/DBIx/Class/Relationship/BelongsTo.pm @@ -6,6 +6,10 @@ use warnings; 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 = !$@; diff --git a/lib/DBIx/Class/Relationship/HasMany.pm b/lib/DBIx/Class/Relationship/HasMany.pm index f30ff50..fdf5dd6 100644 --- a/lib/DBIx/Class/Relationship/HasMany.pm +++ b/lib/DBIx/Class/Relationship/HasMany.pm @@ -7,6 +7,9 @@ sub has_many { 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; diff --git a/lib/DBIx/Class/Relationship/HasOne.pm b/lib/DBIx/Class/Relationship/HasOne.pm index d114a39..432c10e 100644 --- a/lib/DBIx/Class/Relationship/HasOne.pm +++ b/lib/DBIx/Class/Relationship/HasOne.pm @@ -14,6 +14,10 @@ sub has_one { 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" )