[Bps-public-commit] Class-Load branch, master, updated. e4d7d52f60c458ef100fd766f122a5662453d8a3
Shawn Moore
sartak at bestpractical.com
Mon Nov 15 13:01:57 EST 2010
The branch, master has been updated
via e4d7d52f60c458ef100fd766f122a5662453d8a3 (commit)
from def747f4fe71464ee3e5c17eaa39f067acac6f31 (commit)
Summary of changes:
lib/Class/Load.pm | 12 ++++++++++++
t/004-load-double.t | 28 ++++++++++++++++++++++++++++
2 files changed, 40 insertions(+), 0 deletions(-)
create mode 100644 t/004-load-double.t
- Log -----------------------------------------------------------------
commit e4d7d52f60c458ef100fd766f122a5662453d8a3
Author: Kent Fredric <kentfredric at gmail.com>
Date: Sun Nov 14 05:52:16 2010 +1300
Patches to make double-load error conditions more obvious/guarantee a fail on 5.8
diff --git a/lib/Class/Load.pm b/lib/Class/Load.pm
index 4234c8e..62584f4 100644
--- a/lib/Class/Load.pm
+++ b/lib/Class/Load.pm
@@ -42,6 +42,18 @@ sub try_load_class {
: File::Spec->catfile(@parts);
$file .= '.pm';
+ # This says "our diagnostics of the package
+ # say perl's INC status about the file being loaded are
+ # wrong", so we delete it from $INC, so when we call require(),
+ # perl will *actually* try reloading the file.
+ #
+ # If the file is already in $INC, it won't retry,
+ # And on 5.8, it won't fail either!
+ #
+ # The extra benefit of this trick, is it helps even on
+ # 5.10, as instead of dying with "Compilation failed",
+ # it will die with the actual error, and thats a win-win.
+ delete $INC{$file};
return 1 if eval {
local $SIG{__DIE__} = 'DEFAULT';
require $file;
diff --git a/t/004-load-double.t b/t/004-load-double.t
new file mode 100644
index 0000000..b2b70da
--- /dev/null
+++ b/t/004-load-double.t
@@ -0,0 +1,28 @@
+use strict;
+use warnings;
+
+use Test::More tests => 2;
+use Class::Load ':all';
+use Test::Fatal;
+
+use lib 't/lib';
+
+# This test does 2 things.
+# Firstly, confirm that on 5.8, load_class will
+# still throw an exception , even if its been loaded before:
+#
+# eval { require Foo; }; require Foo; # doesn't error on 5.8
+#
+# Secondly, to ensure errors thrown are useful.
+# ( As without the code in load_class to delete $INC{file}
+# it will just die with "COMPILATION ERROR", which is
+# not useful )
+#
+like( exception {
+ load_class('Class::Load::SyntaxError');
+}, qr/syntax error/ );
+
+like( exception {
+ load_class('Class::Load::SyntaxError');
+}, qr/syntax error/ );
+
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list