fixed up 90ensure_class_loaded.t
Justin Guenther [Mon, 19 Jun 2006 00:04:56 +0000 (00:04 +0000)]
lib/DBIx/Class/Componentised.pm
t/90ensure_class_loaded.t
t/lib/DBICTest/SyntaxErrorComponent1.pm [copied from t/lib/DBICTest/SyntaxErrorComponent.pm with 77% similarity]
t/lib/DBICTest/SyntaxErrorComponent2.pm [moved from t/lib/DBICTest/SyntaxErrorComponent.pm with 77% similarity]

index 42dec25..5841afa 100644 (file)
@@ -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
index 4da8a75..c901d06 100644 (file)
@@ -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;
similarity index 77%
copy from t/lib/DBICTest/SyntaxErrorComponent.pm
copy to t/lib/DBICTest/SyntaxErrorComponent1.pm
index 27f7ad8..3fb5045 100644 (file)
@@ -1,6 +1,6 @@
 #   belongs to t/run/90ensure_class_loaded.tl
 package # hide from PAUSE 
-    DBICTest::SyntaxErrorComponent;
+    DBICTest::SyntaxErrorComponent1;
 use warnings;
 use strict;
 
similarity index 77%
rename from t/lib/DBICTest/SyntaxErrorComponent.pm
rename to t/lib/DBICTest/SyntaxErrorComponent2.pm
index 27f7ad8..ac6cfb8 100644 (file)
@@ -1,6 +1,6 @@
 #   belongs to t/run/90ensure_class_loaded.tl
 package # hide from PAUSE 
-    DBICTest::SyntaxErrorComponent;
+    DBICTest::SyntaxErrorComponent2;
 use warnings;
 use strict;