File Coverage

blib/lib/experimentals.pm
Criterion Covered Total %
statement 23 32 71.8
branch 3 8 37.5
condition n/a
subroutine 7 8 87.5
pod n/a
total 33 48 68.7


line stmt bran cond sub pod time code
1             package experimentals;
2             our $VERSION = '0.019';
3              
4 2     2   995 use 5.010;
  2         6  
5 2     2   9 use strict;
  2         2  
  2         31  
6 2     2   8 use warnings;
  2         2  
  2         55  
7 2     2   19 use feature ();
  2         4  
  2         205  
8              
9             # Module enables/disables these features...
10             my %FEATURES
11             = map { $_ => 1 } ( $] > 5.015006 ? keys %feature::feature
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             my %WARNINGS = map { $_ => 1 } grep { /^experimental::/ } keys %warnings::Offsets;
19              
20             # In -report mode, the code is not run...
21             my $DO_NOT_RUN;
22             {
23 2     2   11 no warnings 'void';
  2         3  
  2         631  
24             INIT { exit if $DO_NOT_RUN; }
25             }
26              
27             # Grab and reformat experimental warnings (when assigned to $SIG{__WARN__})...
28             sub _report_experimentals {
29 0     0   0 my $warning = "@_";
30              
31             # Reformat any experimental warning (ignoring anything else)...
32 0 0       0 if ($warning =~ m{\A(.*) is experimental\b(?:.*) at (.* line \d+)}) {
33 0         0 printf {*STDERR} "%s:\t%s\n", $2, ucfirst $1;
  0         0  
34             }
35             }
36              
37             # Handle 'use experimentals'...
38             sub import {
39              
40             # Always enable all available features...
41 4     4   3026 feature->import(keys %FEATURES);
42              
43             # Turn on utf8 if the feature requires it...
44 4 50       14 if ($FEATURES{ extra_paired_delimiters }) {
45 0         0 require utf8;
46 0         0 utf8->import();
47             }
48              
49             # Are we reporting???
50 4 50       8 my $reporting = grep { defined $_ && lc($_) eq '-report' } @_;
  4         18  
51              
52             # If not reporting, disable all warnings about experimental features...
53 4 50       8 if (!$reporting) {
54 4         368 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         0 warnings->import(keys %WARNINGS);
61              
62             # Install the code to grab them...
63 0         0 $SIG{__WARN__} = \&_report_experimentals;
64              
65             # Prevent actual code execution...
66 0         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     2   659 feature->import(grep { !$WARNINGS{"experimental::$_"} } keys %FEATURES);
  28         164  
74              
75             # Enable experimental warnings...
76 2         104 warnings->import(keys %WARNINGS);
77             }
78              
79             1; # Magic true value required at end of module
80              
81             __END__