| 1 | package experimentals; | ||||||||||||||||||
| 2 | 2 | our $VERSION = '0.019'; | |||||||||||||||||
| 3 | |||||||||||||||||||
| 4 | 2 | ▶ | use 5.010; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 5 | 2 | ▶ | use strict; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 6 | 2 | ▶ | use warnings; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 7 | 2 | ▶ | use feature (); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 8 | |||||||||||||||||||
| 9 | # Module enables/disables these features... | ||||||||||||||||||
| 10 | my %FEATURES | ||||||||||||||||||
| 11 | 2 | ▶ | = map { $_ => 1 } ( $] > 5.015006 ? keys %feature::feature | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 12 | : $] >= 5.011002 ? qw< say state switch unicode_strings > | ||||||||||||||||||
| 13 | : $] >= 5.010000 ? qw< say state switch > | ||||||||||||||||||
| 14 | : qw< > | ||||||||||||||||||
| 15 | ); | ||||||||||||||||||
| 16 | |||||||||||||||||||
| 17 | # Module disables these warnings... | ||||||||||||||||||
| 18 | 2 | my %WARNINGS = map { $_ => 1 } grep { /^experimental::/ } keys %warnings::Offsets; | |||||||||||||||||
| 19 | |||||||||||||||||||
| 20 | # In -report mode, the code is not run... | ||||||||||||||||||
| 21 | 2 | my $DO_NOT_RUN; | |||||||||||||||||
| 22 | { | ||||||||||||||||||
| 23 | 2 | ▶ | no warnings 'void'; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 24 | INIT { exit if $DO_NOT_RUN; } | ||||||||||||||||||
| 25 | } | ||||||||||||||||||
| 26 | |||||||||||||||||||
| 27 | # Grab and reformat experimental warnings (when assigned to $SIG{__WARN__})... | ||||||||||||||||||
| 28 | 2 | sub _report_experimentals { | |||||||||||||||||
| 29 | 0 | ▶ | my $warning = "@_"; | ||||||||||||||||
|
Subroutine
_report_experimentals: not called CC=2 SCAR=17.9
| |||||||||||||||||||
| 30 | |||||||||||||||||||
| 31 | # Reformat any experimental warning (ignoring anything else)... | ||||||||||||||||||
| 32 | 0 | ▶ | if ($warning =~ m{\A(.*) is experimental\b(?:.*) at (.* line \d+)}) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 33 | 0 | printf {*STDERR} "%s:\t%s\n", $2, ucfirst $1; | |||||||||||||||||
| 34 | } | ||||||||||||||||||
| 35 | } | ||||||||||||||||||
| 36 | |||||||||||||||||||
| 37 | # Handle 'use experimentals'... | ||||||||||||||||||
| 38 | sub import { | ||||||||||||||||||
| 39 | |||||||||||||||||||
| 40 | # Always enable all available features... | ||||||||||||||||||
| 41 | 4 | ▶ | feature->import(keys %FEATURES); | ||||||||||||||||
|
Subroutine
import: called CC=4 SCAR=15.5
| |||||||||||||||||||
| 42 | |||||||||||||||||||
| 43 | # Turn on utf8 if the feature requires it... | ||||||||||||||||||
| 44 | 4 | ▶ | if ($FEATURES{ extra_paired_delimiters }) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 45 | 4 | require utf8; | |||||||||||||||||
| 46 | 4 | utf8->import(); | |||||||||||||||||
| 47 | } | ||||||||||||||||||
| 48 | |||||||||||||||||||
| 49 | # Are we reporting??? | ||||||||||||||||||
| 50 | 4 | ▶ | my $reporting = grep { defined $_ && lc($_) eq '-report' } @_; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 51 | |||||||||||||||||||
| 52 | # If not reporting, disable all warnings about experimental features... | ||||||||||||||||||
| 53 | 4 | ▶ | if (!$reporting) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 54 | 4 | warnings->unimport(keys %WARNINGS); | |||||||||||||||||
| 55 | } | ||||||||||||||||||
| 56 | |||||||||||||||||||
| 57 | # Otherwise, set up a filter to grab and reformat experimental warnings... | ||||||||||||||||||
| 58 | else { | ||||||||||||||||||
| 59 | # Enable the warnings we're going to grab... | ||||||||||||||||||
| 60 | 0 | warnings->import(keys %WARNINGS); | |||||||||||||||||
| 61 | |||||||||||||||||||
| 62 | # Install the code to grab them... | ||||||||||||||||||
| 63 | 0 | $SIG{__WARN__} = \&_report_experimentals; | |||||||||||||||||
| 64 | |||||||||||||||||||
| 65 | # Prevent actual code execution... | ||||||||||||||||||
| 66 | 0 | $DO_NOT_RUN = 1; | |||||||||||||||||
| 67 | } | ||||||||||||||||||
| 68 | } | ||||||||||||||||||
| 69 | |||||||||||||||||||
| 70 | # Handle 'no experimentals'... | ||||||||||||||||||
| 71 | sub unimport { | ||||||||||||||||||
| 72 | # Enable features that don't have experimental warnings... | ||||||||||||||||||
| 73 | 2 | ▶ | feature->import(grep { !$WARNINGS{"experimental::$_"} } keys %FEATURES); | ||||||||||||||||
|
Subroutine
unimport: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 74 | |||||||||||||||||||
| 75 | # Enable experimental warnings... | ||||||||||||||||||
| 76 | 2 | warnings->import(keys %WARNINGS); | |||||||||||||||||
| 77 | } | ||||||||||||||||||
| 78 | |||||||||||||||||||
| 79 | 2 | 1; # Magic true value required at end of module | |||||||||||||||||
| 80 | |||||||||||||||||||
| 81 | __END__ | ||||||||||||||||||