From: Justin Guenther Date: Mon, 19 Jun 2006 00:04:56 +0000 (+0000) Subject: fixed up 90ensure_class_loaded.t X-Git-Tag: v0.07002~75^2~104 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9d3d92abe4fefa68f63ba4c90eb60f9e899911d4;p=dbsrgits%2FDBIx-Class.git fixed up 90ensure_class_loaded.t --- diff --git a/lib/DBIx/Class/Componentised.pm b/lib/DBIx/Class/Componentised.pm index 42dec25..5841afa 100644 --- a/lib/DBIx/Class/Componentised.pm +++ b/lib/DBIx/Class/Componentised.pm @@ -64,10 +64,14 @@ sub _load_components { # # TODO: handle ->has_many('rel', 'Class'...) instead of # ->has_many('rel', 'Some::Schema::Class'...) +# +# BUG: For some reason, packages with syntax errors are added to %INC on +# require sub ensure_class_loaded { my ($class, $f_class) = @_; return if Class::Inspector->loaded($f_class); - require $f_class; + eval "require $f_class"; # require needs a bareword or filename + $class->throw_exception($@) if ($@); } # Returns true if the specified class is installed or already loaded, false diff --git a/t/90ensure_class_loaded.t b/t/90ensure_class_loaded.t index 4da8a75..c901d06 100644 --- a/t/90ensure_class_loaded.t +++ b/t/90ensure_class_loaded.t @@ -63,10 +63,13 @@ ok( Class::Inspector->loaded('DBICTest::FakeComponent'), $warning =~ /Missing operator before/ ); }; - eval { $schema->load_optional_class('DBICTest::SyntaxErrorComponent') }; - like( $@, qr/syntax error/, 'DBICTest::ErrorComponent threw ok' ); - eval { $schema->ensure_class_loaded('DBICTest::SyntaxErrorComponent') }; - like( $@, qr/syntax error/, 'DBICTest::ErrorComponent threw ok' ); + + eval { $schema->ensure_class_loaded('DBICTest::SyntaxErrorComponent1') }; + like( $@, qr/syntax error/, + 'ensure_class_loaded(DBICTest::SyntaxErrorComponent1) threw ok' ); + eval { $schema->load_optional_class('DBICTest::SyntaxErrorComponent2') }; + like( $@, qr/syntax error/, + 'load_optional_class(DBICTest::SyntaxErrorComponent2) threw ok' ); } 1; diff --git a/t/lib/DBICTest/SyntaxErrorComponent.pm b/t/lib/DBICTest/SyntaxErrorComponent1.pm similarity index 77% copy from t/lib/DBICTest/SyntaxErrorComponent.pm copy to t/lib/DBICTest/SyntaxErrorComponent1.pm index 27f7ad8..3fb5045 100644 --- a/t/lib/DBICTest/SyntaxErrorComponent.pm +++ b/t/lib/DBICTest/SyntaxErrorComponent1.pm @@ -1,6 +1,6 @@ # belongs to t/run/90ensure_class_loaded.tl package # hide from PAUSE - DBICTest::SyntaxErrorComponent; + DBICTest::SyntaxErrorComponent1; use warnings; use strict; diff --git a/t/lib/DBICTest/SyntaxErrorComponent.pm b/t/lib/DBICTest/SyntaxErrorComponent2.pm similarity index 77% rename from t/lib/DBICTest/SyntaxErrorComponent.pm rename to t/lib/DBICTest/SyntaxErrorComponent2.pm index 27f7ad8..ac6cfb8 100644 --- a/t/lib/DBICTest/SyntaxErrorComponent.pm +++ b/t/lib/DBICTest/SyntaxErrorComponent2.pm @@ -1,6 +1,6 @@ # belongs to t/run/90ensure_class_loaded.tl package # hide from PAUSE - DBICTest::SyntaxErrorComponent; + DBICTest::SyntaxErrorComponent2; use warnings; use strict;