From: Vincent Pit Date: Tue, 7 Sep 2010 14:51:33 +0000 (+0200) Subject: Disable strict and warnings when evaluating the code X-Git-Tag: v0.06~10 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FPerl-Critic-Policy-Dynamic-NoIndirect.git;a=commitdiff_plain;h=6e8dbf3b02e4df3a7304b7acbe47037575fc952d Disable strict and warnings when evaluating the code Also don't wrap the code inside a real block, as this changes the behaviour of last and redo. --- diff --git a/lib/Perl/Critic/Policy/Dynamic/NoIndirect.pm b/lib/Perl/Critic/Policy/Dynamic/NoIndirect.pm index 3528d0b..068ab88 100644 --- a/lib/Perl/Critic/Policy/Dynamic/NoIndirect.pm +++ b/lib/Perl/Critic/Policy/Dynamic/NoIndirect.pm @@ -58,24 +58,25 @@ sub violates_dynamic { my @errs; my $wrapper = <<" WRAPPER"; - { return; package main; - no indirect hook => sub { push \@errs, [ \@_ ] }; - { - ; + my \$hook; + BEGIN { \$hook = sub { push \@errs, [ \@_ ] } } + no strict; + no warnings; + no indirect hook => \$hook; + do { #line 1 "$file" $src } - } WRAPPER { local ($@, *_); eval $wrapper; ## no critic - if ($@) { + if (my $err = $@) { require Carp; - Carp::confess("Couldn't compile the source wrapper: $@"); + Carp::croak("Couldn't compile the source wrapper: $err"); } } diff --git a/t/10-basic.t b/t/10-basic.t index 314f4f5..146c6a1 100644 --- a/t/10-basic.t +++ b/t/10-basic.t @@ -5,8 +5,8 @@ use warnings; my ($tests, $reports, $subtests); BEGIN { - $tests = 27; - $reports = 42; + $tests = 28; + $reports = 43; $subtests = 3; } @@ -213,3 +213,7 @@ our $obj; my $x = meh { new $obj } new X; ---- [ 'meh', '{', 2, 9 ], [ 'new', '$obj', 2, 15 ], [ 'new', 'X', 2, 26 ] +#### +my $x = $invalid_global_when_strict_is_on; new X; +---- +[ 'new', 'X', 1, 44 ]