X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2Fstrictures.git;a=blobdiff_plain;f=lib%2Fstrictures.pm;h=a865d7736aff1ddf789d20a27d3d8d1a32653255;hp=77983281e498743839e6c40719c441222295ce1a;hb=8f0df510535f01d82740865bf25e3fc29631c772;hpb=92cde693e78b4540411ac18d8b0fc759a4249a2a diff --git a/lib/strictures.pm b/lib/strictures.pm index 7798328..a865d77 100644 --- a/lib/strictures.pm +++ b/lib/strictures.pm @@ -21,7 +21,7 @@ sub VERSION { goto &UNIVERSAL::VERSION; } -our $extra_load_states; +our %extra_load_states; our $Smells_Like_VCS; @@ -52,6 +52,15 @@ sub _enable_1 { strict->import; warnings->import(FATAL => 'all'); + _load_extras(qw(indirect multidimensional bareword::filehandles)) + or return; + indirect->unimport(':fatal') if $extra_load_states{indirect}; + multidimensional->unimport if $extra_load_states{multidimensional}; + bareword::filehandles->unimport if $extra_load_states{'bareword::filehandles'}; +} + +sub _load_extras { + my @extras = @_; my $extra_tests = do { if (exists $ENV{PERL_STRICTURES_EXTRA}) { if (_PERL_LT_5_8_4 and $ENV{PERL_STRICTURES_EXTRA}) { @@ -60,7 +69,7 @@ sub _enable_1 { } $ENV{PERL_STRICTURES_EXTRA}; } elsif (! _PERL_LT_5_8_4) { - (caller(3))[1] =~ /^(?:t|xt|lib|blib)[\\\/]/ + (caller(4))[1] =~ /^(?:t|xt|lib|blib)[\\\/]/ and defined $Smells_Like_VCS ? $Smells_Like_VCS : ( $Smells_Like_VCS = !!( -e '.git' || -e '.svn' || -e '.hg' @@ -69,26 +78,27 @@ sub _enable_1 { )) } }; - if ($extra_tests) { - $extra_load_states ||= do { + return + unless $extra_tests; - my (%rv, @failed); - foreach my $mod (qw(indirect multidimensional bareword::filehandles)) { - eval "require $mod; \$rv{'$mod'} = 1;" or do { - push @failed, $mod; + my @failed; + foreach my $mod (@extras) { + next + if exists $extra_load_states{$mod}; - # courtesy of the 5.8 require bug - # (we do a copy because 5.16.2 at least uses the same read-only - # scalars for the qw() list and it doesn't seem worth a $^V check) + $extra_load_states{$mod} = eval "require $mod; 1;" or do { + push @failed, $mod; - (my $file = $mod) =~ s|::|/|g; - delete $INC{"${file}.pm"}; - }; - } + #work around 5.8 require bug + (my $file = $mod) =~ s|::|/|g; + delete $INC{"${file}.pm"}; + }; + } - if (@failed) { - my $failed = join ' ', @failed; - print STDERR <unimport(':fatal') if $extra_load_states->{indirect}; - multidimensional->unimport if $extra_load_states->{multidimensional}; - bareword::filehandles->unimport if $extra_load_states->{'bareword::filehandles'}; } + return $extra_tests; } 1;