#
# 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
$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;
# belongs to t/run/90ensure_class_loaded.tl
package # hide from PAUSE
- DBICTest::SyntaxErrorComponent;
+ DBICTest::SyntaxErrorComponent1;
use warnings;
use strict;
# belongs to t/run/90ensure_class_loaded.tl
package # hide from PAUSE
- DBICTest::SyntaxErrorComponent;
+ DBICTest::SyntaxErrorComponent2;
use warnings;
use strict;