From: Jess Robinson Date: Sat, 2 Feb 2008 15:32:22 +0000 (+0000) Subject: Steal class loading code from Class::MOP, which isnt confused by __PACKAGE__ X-Git-Tag: 5.7099_04~94 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=7a1958ebdeec92527758a4f23ab9928d28e742c7 Steal class loading code from Class::MOP, which isnt confused by __PACKAGE__ --- diff --git a/lib/Catalyst/Utils.pm b/lib/Catalyst/Utils.pm index fd23d95..670353f 100644 --- a/lib/Catalyst/Utils.pm +++ b/lib/Catalyst/Utils.pm @@ -264,7 +264,9 @@ sub ensure_class_loaded { my $error; { local $@; - eval "require $class;"; + my $file = $class . '.pm'; + $file =~ s{::}{/}g; + eval { CORE::require($file) }; $error = $@; } diff --git a/t/unit_utils_load_class.t b/t/unit_utils_load_class.t index 06924ec..8fe1828 100644 --- a/t/unit_utils_load_class.t +++ b/t/unit_utils_load_class.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 14; +use Test::More tests => 16; use lib "t/lib"; @@ -41,6 +41,11 @@ eval { Catalyst::Utils::ensure_class_loaded("This::Module::Is::Probably::Not::Th ok( $@, "doesn't defatalize" ); like( $@, qr/There\.pm.*\@INC/, "error looks right" ); +undef $@; +eval { Catalyst::Utils::ensure_class_loaded("__PACKAGE__") }; +ok( $@, "doesn't defatalize" ); +like( $@, qr/__PACKAGE__\.pm.*\@INC/, "errors sanely on __PACKAGE__.pm" ); + $@ = "foo"; Catalyst::Utils::ensure_class_loaded("TestApp::View::Dump::Response"); is( $@, "foo", '$@ is untouched' );