Created
May 27, 2016 15:43
-
-
Save dolmen/6e66d8f28d8178feac84623df12d6320 to your computer and use it in GitHub Desktop.
Injecting Sub::StrictSubs into 'use strict'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package strict_subs; | |
use strict; | |
use warnings; | |
use Sub::StrictDecl; | |
sub DB{} | |
sub import | |
{ | |
my $orig = \&strict::import; | |
no warnings 'redefine'; | |
*strict::import = sub { | |
Sub::StrictDecl->import; | |
goto &$orig | |
} | |
} | |
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Test from https://metacpan.org/source/ZEFRAM/Sub-StrictDecl-0.004/t/check.t | |
use warnings; | |
use strict; | |
use Test::More; | |
BEGIN { $^H |= 0x20000; } | |
my $r; | |
$r = eval(q{ | |
#use Sub::StrictDecl; | |
use strict; | |
# sub call | |
if(0) { foo0(); } | |
1; | |
}); | |
is $r, undef; | |
like $@, qr/\AUndeclared subroutine &main::foo0/; | |
done_testing; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment