X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2Fautouse.pm;h=cbde3864bf1d6dd1c2711c031353786e645b9e44;hb=cdfe229e642682dd52e04cdd1232a90648b35fe3;hp=8057d18f657284d879534e10a9701b1039cbdcdb;hpb=08e0cdb53693ab205dfafc01b835c6f8381d1e83;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/autouse.pm b/lib/autouse.pm index 8057d18..cbde386 100644 --- a/lib/autouse.pm +++ b/lib/autouse.pm @@ -1,9 +1,9 @@ package autouse; #use strict; # debugging only -use 5.003_90; # ->can, for my $var +use 5.006; # use warnings -$autouse::VERSION = '1.02'; +$autouse::VERSION = '1.06'; $autouse::DEBUG ||= 0; @@ -50,11 +50,10 @@ sub import { my $load_sub = sub { unless ($INC{$pm}) { - eval {require $pm}; - die if $@; + require $pm; vet_import $module; } - no warnings 'redefine'; + no warnings qw(redefine prototype); *$closure_import_func = \&{"${module}::$closure_func"}; print "autousing $module; " ."imported $closure_func as $closure_import_func\n" @@ -63,7 +62,8 @@ sub import { }; if (defined $proto) { - *$closure_import_func = eval "sub ($proto) { &\$load_sub }"; + *$closure_import_func = eval "sub ($proto) { goto &\$load_sub }" + || die; } else { *$closure_import_func = $load_sub; } @@ -73,9 +73,10 @@ sub import { sub vet_import ($) { my $module = shift; if (my $import = $module->can('import')) { - croak "autoused module has unique import() method" + croak "autoused module $module has unique import() method" unless defined(&Exporter::import) - && $import == \&Exporter::import; + && ($import == \&Exporter::import || + $import == \&UNIVERSAL::import) } }