Created
February 21, 2013 01:02
-
-
Save belden/5001086 to your computer and use it in GitHub Desktop.
lib::with::preamble places a code hook at the beginning of @inc, and then relies upon that hook remaining at $INC[0]. In a suitably complicated codebase, there is likely to be one module which modifies the head of @inc, and some subsequent module which violates the constraints that lib::with::preamble is intended to enforce. Included in the patc…
This file contains hidden or 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
diff --git a/Makefile.PL b/Makefile.PL | |
index cfc4d6d..8e90634 100644 | |
--- Makefile.PL | |
+++ Makefile.PL | |
@@ -8,5 +8,8 @@ WriteMakefile( | |
NAME => 'lib-with-preamble', | |
VERSION_FROM => 'lib/lib/with/preamble.pm', | |
PM_FILTER => 'perl my/filter', | |
- PREREQ_PM => { 'PerlIO::via::dynamic' => 0.02 }, | |
+ PREREQ_PM => { | |
+ 'PerlIO::via::dynamic' => 0.02, | |
+ 'Array::Sticky' => 0.01, | |
+ }, | |
); | |
diff --git a/lib/lib/with/preamble.pm b/lib/lib/with/preamble.pm | |
index a6ad586..744c540 100644 | |
--- lib/lib/with/preamble.pm | |
+++ lib/lib/with/preamble.pm | |
@@ -4,6 +4,7 @@ use strict; | |
use warnings FATAL => 'all'; | |
use File::Spec; | |
use PerlIO::via::dynamic; | |
+use Array::Sticky::INC; | |
our $VERSION = '0.001000'; # 0.1.0 | |
@@ -31,6 +32,7 @@ sub import { | |
my ($class, $preamble, @libs) = @_; | |
return unless defined($preamble) and @libs; | |
unshift @INC, [ \&require_with_preamble, $preamble, @libs ]; | |
+ Array::Sticky::INC->make_sticky; | |
} | |
1; | |
diff --git a/t/lib/has_strict_violation.pm b/t/lib/has_strict_violation.pm | |
new file mode 100644 | |
index 0000000..68547d4 | |
--- /dev/null | |
+++ t/lib/has_strict_violation.pm | |
@@ -0,0 +1,5 @@ | |
+package has_strict_violation; | |
+ | |
+$y = 10; | |
+ | |
+1; | |
diff --git a/t/lib/is_okay.pm b/t/lib/is_okay.pm | |
new file mode 100644 | |
index 0000000..e272ccf | |
--- /dev/null | |
+++ t/lib/is_okay.pm | |
@@ -0,0 +1,6 @@ | |
+package is_okay; | |
+ | |
+use screws_up_INC; | |
+use has_strict_violation; | |
+ | |
+1; | |
diff --git a/t/lib/screws_up_INC.pm b/t/lib/screws_up_INC.pm | |
new file mode 100644 | |
index 0000000..26b34eb | |
--- /dev/null | |
+++ t/lib/screws_up_INC.pm | |
@@ -0,0 +1,5 @@ | |
+package screws_up_INC; | |
+ | |
+sub import { shift @INC } | |
+ | |
+1; | |
diff --git a/t/sticky-inc-hooks.t b/t/sticky-inc-hooks.t | |
new file mode 100644 | |
index 0000000..ab57186 | |
--- /dev/null | |
+++ t/sticky-inc-hooks.t | |
@@ -0,0 +1,10 @@ | |
+#!/usr/bin/env perl | |
+ | |
+use strict; | |
+use warnings; | |
+use Test::More tests => 1; | |
+ | |
+use lib::with::preamble 'use strict;', 't/lib', './lib'; | |
+ | |
+eval { require is_okay }; | |
+like( $@, qr/Global symbol "\$y" requires explicit package name.*has_strict_violation\.pm line 3/, 'our @INC hook stays in place' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment