Deparse: Ignore strict hh hints
authorFather Chrysostomos <sprout@cpan.org>
Sat, 24 Dec 2011 06:09:00 +0000 (22:09 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 24 Dec 2011 06:09:19 +0000 (22:09 -0800)
As of 5.15.6, strict.pm puts hints in %^H.  B::Deparse still deparses
strict hints in $^H with ‘use strict’.  Strictly speaking, deparsing
$^H  hints with ‘use strict’ is not strictly correct any more, because
the result of ‘eval 'use v5.10; ...'’ within the same scope is differ-
ent, in that ‘use v5.10’ will disable strictures enabled only through
$^H, but will not disable those enabled also through %^H.

(Strict entries in %^H strictly indicate that strict.pm is overriding
any version declaration.  They are always set to undef.)

So the correct way to deparse $^H without %^H would be ‘use 5.011’ or
‘use 5.012’ or ‘use 5.011001000000001’, which all work.  The correct
way to deparse $^H *with* %^H is ‘use strict’.

Determining the actual version number to use is a problem.  It is
nowhere to be seen in the op tree.  It is visible in the implied BEGIN
block (BEGIN{require 5.012}).  Due to limitations in Perl itself,
it is not possible to know exactly where the BEGIN block should go,
so trying to pair up $^H changes with BEGIN blocks could never work
reliably.  Simply guessing the version number and printing one the
code did not contain would cause more confusion than the strict
hints in %^H.

Since B::Deparse has special-cased strict mode as far as I can remem-
ber, always putting it in the right place, falling back to relying
BEGIN blocks (collapsing them to version declarations) would be a
regression.

So it seems the best choice is simply to suppress strict hints in %^H
and deparse strict as it has always been deparsed.  It’s not strictly
correct, but neither are the alternatives, and it seems the least bad.

dist/B-Deparse/Deparse.pm
dist/B-Deparse/t/deparse.t

index 6493f6e..bcc3608 100644 (file)
@@ -1526,6 +1526,9 @@ my %ignored_hints = (
     'open<' => 1,
     'open>' => 1,
     ':'     => 1,
+    'strict/refs' => 1,
+    'strict/subs' => 1,
+    'strict/vars' => 1,
 );
 
 sub declare_hinthash {
index 1781349..a40e3f5 100644 (file)
@@ -224,6 +224,12 @@ q<{
     print "@-";
 }>, 'no need to curly around to interpolate "@-"');
 
+# Strict hints in %^H are mercilessly suppressed
+$a =
+  `$^X $path "-MO=Deparse" -e "use strict; print;" 2>&1`;
+unlike($a, qr/BEGIN/,
+    "Deparse does not emit strict hh hints");
+
 done_testing();
 
 __DATA__