Last active
June 30, 2020 14:49
-
-
Save toddr/0c280d3a4f5951776cd0d1e6d49dba11 to your computer and use it in GitHub Desktop.
This module enables all features and sets strict and warnings on by default with experimental warnings off. WARNING: this is not the definitive list of what will be in perl 7 but provides a way to test what might break in perl 7 but on 5.30.0
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 compat::perl5; | |
# This helps hint to perl 7+ what level of compatibility this code has with future versions of perl. | |
# use compat::perl5 should be the first thing in your code. Especially before use strict, warnings, v5.XXX, or feature. | |
BEGIN { | |
$] <= 8 or die("This code is incompatible with Perl 8. Please see XXX for more information."); | |
if ( $] > 6 ) { | |
warn_quietly_once("This code is being run using Perl $]. It should be updated or may break in Perl 8. See YYY for more information."); | |
} | |
} | |
sub import { | |
# no warnings; | |
${^WARNING_BITS} = undef; | |
# perl -e'my $h; BEGIN { $h = $^H } printf("\$^H = 0x%08X\n", $h); ' | |
$^H = 0x0; | |
%^H = (); | |
} | |
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
package compat::perl7; | |
# use compat::perl7 enables perl 5 code to function in a perl 7-ish way as much as possible compared to the version you are running. | |
# it also is a hint to both tools and the compiler what the level of compatibility is with future versions of the language. | |
BEGIN { | |
# This code is a proof of concept provided against 5.30. In order for this code to work on other versions of perl | |
# we would need to generate it via p7.pm.PL as part of shipping it to CPAN. | |
$] >= 5.030 && $] < 5.031 or die("Perl 5.30 is required to use this module."); | |
} | |
sub import { | |
# use warnings; no warnings qw/experimental/; | |
# perl -e'use warnings; no warnings qw/experimental/; my $w; BEGIN {$w = ${^WARNING_BITS} } print unpack("H*", $w) . "\n"' | |
${^WARNING_BITS} = pack( "H*", "55555555555555555555555515000440050454" ); | |
# use strict; use utf8; | |
# perl -MData::Dumper -e'my $h; use strict; use utf8; use feature (qw/bitwise current_sub declared_refs evalbytes fc postderef_qq refaliasing say signatures state switch unicode_eval unicode_strings/); BEGIN { $h = $^H } printf("\$^H = 0x%08X\n", $h); print Dumper \%^H; ' | |
$^H = 0x1C820FE2; | |
%^H = ( | |
'feature___SUB__' => 1, | |
'feature_bitwise' => 1, | |
'feature_evalbytes' => 1, | |
'feature_fc' => 1, | |
'feature_myref' => 1, | |
'feature_postderef_qq' => 1, | |
'feature_refaliasing' => 1, | |
'feature_say' => 1, | |
'feature_signatures' => 1, | |
'feature_state' => 1, | |
'feature_switch' => 1, | |
'feature_unicode' => 1, | |
'feature_unieval' => 1 | |
); | |
} | |
1; |
Will this ever be non-secret? I was thinking about doing something similar.
I don't think I realized it was secret.
fixed.
note that https://github.com/Perl/perl5/blob/core-p7/regen/pX.pl provides a way to generate these two files
you can view the generated files here:
- p7: https://github.com/Perl/perl5/blob/core-p7/lib/p7.pm
- p5: https://github.com/Perl/perl5/blob/core-p7/lib/p5.pm
We should close this gist and move the discussion to the repo itself.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
note older versions don't understand newer "use v5.44" and get very angry if you use them.