From: Graham Knop Date: Wed, 1 Jul 2015 10:31:36 +0000 (-0400) Subject: get hints from strictures as late as possible X-Git-Tag: v1.003005~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6c8bf56cd4942ec40e37a6db79d4bab121e1cff8;p=p5sagit%2FEval-WithLexicals.git get hints from strictures as late as possible strictures v1 enables all fatal warnings, which included anything custom registered by other modules. Moo will delay loading modules for as long as possible, which means some things, like Class::Method::Modifiers, won't be loaded until the WithHintPersistence role is applied at object creation time. This may what causes vars.pm to be loaded, which registers a warning category and can break the test. If we delay checking the expected hints until immediately before going the eval test, all warning categories should be loaded. --- diff --git a/t/hints.t b/t/hints.t index 8d30d78..7040b42 100644 --- a/t/hints.t +++ b/t/hints.t @@ -4,7 +4,7 @@ use Eval::WithLexicals; use lib 't/lib'; use strictures 1; -use get_strictures_hints qw($strictures_hints $strictures_warn); +use get_strictures_hints; my $eval = Eval::WithLexicals->with_plugins("HintPersistence")->new(prelude => ''); @@ -19,6 +19,7 @@ is_deeply( 'Lexical not stored' ); +my ($strictures_hints, $strictures_warn) = get_strictures_hints::hints(); $eval->eval('use strictures 1'); { diff --git a/t/lib/get_strictures_hints.pm b/t/lib/get_strictures_hints.pm index f3f36fd..0af3e90 100644 --- a/t/lib/get_strictures_hints.pm +++ b/t/lib/get_strictures_hints.pm @@ -1,21 +1,21 @@ package get_strictures_hints; -local $ENV{PERL_STRICTURES_EXTRA} = 0; -our $strictures_hints; -our $strictures_warn; +sub hints { + local $ENV{PERL_STRICTURES_EXTRA} = 0; + my $strictures_hints; + my $strictures_warn; -eval q{ - use strictures 1; - BEGIN { - # Find the hint value that 'use strictures 1' sets on this perl. - $strictures_hints = $^H; - $strictures_warn = ${^WARNING_BITS}; - }; - 1; -} or die $@; + eval q{ + use strictures 1; + BEGIN { + # Find the hint value that 'use strictures 1' sets on this perl. + $strictures_hints = $^H; + $strictures_warn = ${^WARNING_BITS}; + }; + 1; + } or die $@; -require Exporter; -*import = \&Exporter::import; -our @EXPORT = qw($strictures_hints $strictures_warn); + return ($strictures_hints, $strictures_warn); +} 1;