From: Dave Rolsky Date: Fri, 29 Aug 2008 21:53:25 +0000 (+0000) Subject: Some small tweak to how we load XS, most notably shutting up X-Git-Tag: 0.64_07~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d7bda11497e94ce009fcc4547a0d26ec0da2a123;p=gitmo%2FClass-MOP.git Some small tweak to how we load XS, most notably shutting up subroutine redefined warnings on earlier Perls (5.8.5 spits them out, probably others). Also only load Sub::Identify if needed. --- diff --git a/lib/Class/MOP.pm b/lib/Class/MOP.pm index 948d5ef..36d5bf1 100644 --- a/lib/Class/MOP.pm +++ b/lib/Class/MOP.pm @@ -11,8 +11,6 @@ use MRO::Compat; use Carp 'confess'; use Scalar::Util 'weaken'; -use Sub::Identify 'get_code_info'; - BEGIN { local $@; eval { @@ -55,19 +53,34 @@ our $AUTHORITY = 'cpan:STEVAN'; # after that everything is loaded, if we're allowed try to load faster XS # versions of various things -unless ($ENV{CLASS_MOP_NO_XS}) { +_try_load_xs() or _load_pure_perl(); + +sub _try_load_xs { + return if $ENV{CLASS_MOP_NO_XS}; + my $e = do { local $@; eval { require XSLoader; + # just doing this - no warnings 'redefine' - doesn't work + # for some reason + local $^W = 0; __PACKAGE__->XSLoader::load($XS_VERSION); }; $@; }; die $e if $e && $e !~ /object version|loadable object/; + + return $e ? 0 : 1; } +sub _load_pure_perl { + require Sub::Identify; + Sub::Identify->import('get_code_info'); +} + + { # Metaclasses are singletons, so we cache them here. # there is no need to worry about destruction though