Skip to content

Instantly share code, notes, and snippets.

@dolmen
Created May 27, 2016 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dolmen/6e66d8f28d8178feac84623df12d6320 to your computer and use it in GitHub Desktop.
Save dolmen/6e66d8f28d8178feac84623df12d6320 to your computer and use it in GitHub Desktop.
Injecting Sub::StrictSubs into 'use strict'
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;
# 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