| 1 | package experimental; | ||||||||||||||||||||||||||||||
| 2 | 1 | $experimental::VERSION = '0.030'; | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use version (); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | BEGIN { eval { require feature } }; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Carp qw/croak carp/; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||
| 10 | 1 | my %warnings = map { $_ => 1 } grep { /^experimental::/ } keys %warnings::Offsets; | |||||||||||||||||||||||||||||
| 11 | 1 | my %removed_warnings = map { $_ => 1 } grep { /^experimental::/ } keys %warnings::NoOp; | |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | my %features = map { $_ => 1 } $] > 5.015006 ? keys %feature::feature : do { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 13 | 0 | my @features; | |||||||||||||||||||||||||||||
| 14 | 0 | ▶ | if ($] >= 5.010) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 15 | 0 | push @features, qw/switch say state/; | |||||||||||||||||||||||||||||
| 16 | 0 | ▶ | push @features, 'unicode_strings' if $] > 5.011002; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||
| 18 | 0 | @features; | |||||||||||||||||||||||||||||
| 19 | }; | ||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||
| 21 | 1 | my %min_version = ( | |||||||||||||||||||||||||||||
| 22 | args_array_with_signatures => '5.20.0', | ||||||||||||||||||||||||||||||
| 23 | array_base => '5', | ||||||||||||||||||||||||||||||
| 24 | autoderef => '5.14.0', | ||||||||||||||||||||||||||||||
| 25 | bitwise => '5.22.0', | ||||||||||||||||||||||||||||||
| 26 | builtin => '5.35.7', | ||||||||||||||||||||||||||||||
| 27 | const_attr => '5.22.0', | ||||||||||||||||||||||||||||||
| 28 | current_sub => '5.16.0', | ||||||||||||||||||||||||||||||
| 29 | declared_refs => '5.26.0', | ||||||||||||||||||||||||||||||
| 30 | defer => '5.35.4', | ||||||||||||||||||||||||||||||
| 31 | evalbytes => '5.16.0', | ||||||||||||||||||||||||||||||
| 32 | extra_paired_delims => '5.35.9', | ||||||||||||||||||||||||||||||
| 33 | fc => '5.16.0', | ||||||||||||||||||||||||||||||
| 34 | for_list => '5.35.5', | ||||||||||||||||||||||||||||||
| 35 | isa => '5.31.7', | ||||||||||||||||||||||||||||||
| 36 | lexical_topic => '5.10.0', | ||||||||||||||||||||||||||||||
| 37 | lexical_subs => '5.18.0', | ||||||||||||||||||||||||||||||
| 38 | postderef => '5.20.0', | ||||||||||||||||||||||||||||||
| 39 | postderef_qq => '5.20.0', | ||||||||||||||||||||||||||||||
| 40 | refaliasing => '5.22.0', | ||||||||||||||||||||||||||||||
| 41 | regex_sets => '5.18.0', | ||||||||||||||||||||||||||||||
| 42 | say => '5.10.0', | ||||||||||||||||||||||||||||||
| 43 | smartmatch => '5.10.0', | ||||||||||||||||||||||||||||||
| 44 | signatures => '5.20.0', | ||||||||||||||||||||||||||||||
| 45 | state => '5.10.0', | ||||||||||||||||||||||||||||||
| 46 | switch => '5.10.0', | ||||||||||||||||||||||||||||||
| 47 | try => '5.34.0', | ||||||||||||||||||||||||||||||
| 48 | unicode_eval => '5.16.0', | ||||||||||||||||||||||||||||||
| 49 | unicode_strings => '5.12.0', | ||||||||||||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||||||||||||
| 51 | 1 | my %removed_in_version = ( | |||||||||||||||||||||||||||||
| 52 | array_base => '5.30.0', | ||||||||||||||||||||||||||||||
| 53 | autoderef => '5.24.0', | ||||||||||||||||||||||||||||||
| 54 | lexical_topic => '5.24.0', | ||||||||||||||||||||||||||||||
| 55 | ); | ||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||
| 57 | 1 | $_ = version->new($_) for values %min_version; | |||||||||||||||||||||||||||||
| 58 | 1 | $_ = version->new($_) for values %removed_in_version; | |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||
| 60 | 1 | my %additional = ( | |||||||||||||||||||||||||||||
| 61 | postderef => ['postderef_qq'], | ||||||||||||||||||||||||||||||
| 62 | switch => ['smartmatch'], | ||||||||||||||||||||||||||||||
| 63 | declared_refs => ['refaliasing'], | ||||||||||||||||||||||||||||||
| 64 | ); | ||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||
| 66 | sub _enable { | ||||||||||||||||||||||||||||||
| 67 | 4 | ▶ | my $pragma = shift; | ||||||||||||||||||||||||||||
|
Subroutine
_enable: called CC=12 SCAR=34.5
| |||||||||||||||||||||||||||||||
| 68 | 4 | ▶ | if ($warnings{"experimental::$pragma"}) { | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 69 | 2 | warnings->unimport("experimental::$pragma"); | |||||||||||||||||||||||||||||
| 70 | 2 | ▶ | feature->import($pragma) if exists $features{$pragma}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 71 | 2 | ▶ | _enable(@{ $additional{$pragma} }) if $additional{$pragma}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||
| 73 | elsif ($features{$pragma}) { | ||||||||||||||||||||||||||||||
| 74 | 1 | feature->import($pragma); | |||||||||||||||||||||||||||||
| 75 | 1 | ▶ | _enable(@{ $additional{$pragma} }) if $additional{$pragma}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||
| 77 | elsif ($removed_warnings{"experimental::$pragma"}) { | ||||||||||||||||||||||||||||||
| 78 | 1 | ▶ | _enable(@{ $additional{$pragma} }) if $additional{$pragma}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||
| 80 | elsif (not exists $min_version{$pragma}) { | ||||||||||||||||||||||||||||||
| 81 | 0 | croak "Can't enable unknown feature $pragma"; | |||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||
| 83 | elsif ($] < $min_version{$pragma}) { | ||||||||||||||||||||||||||||||
| 84 | 0 | my $stable = $min_version{$pragma}->stringify; | |||||||||||||||||||||||||||||
| 85 | 0 | $stable =~ s/^ 5\. ([0-9]?[13579]) \. \d+ $/"5." . ($1 + 1) . ".0"/xe; | |||||||||||||||||||||||||||||
| 86 | 0 | croak "Need perl $stable or later for feature $pragma"; | |||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||
| 88 | ▶ | elsif ($] >= ($removed_in_version{$pragma} || 7)) { | |||||||||||||||||||||||||||||
|
Condition0%0/2
$removed_in_version{$pragma} || 7
MC/DC0%0/1
$removed_in_version{$pragma} || 7
$removed_in_version{$pragma}
Truth table0%0/2
A
A= $removed_in_version{$pragma}
| |||||||||||||||||||||||||||||||
| 89 | 0 | croak "Experimental feature $pragma has been removed from perl in version $removed_in_version{$pragma}"; | |||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||
| 93 | sub import { | ||||||||||||||||||||||||||||||
| 94 | 3 | ▶ | my ($self, @pragmas) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
import: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||
| 96 | 3 | for my $pragma (@pragmas) { | |||||||||||||||||||||||||||||
| 97 | 3 | _enable($pragma); | |||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||
| 99 | 3 | return; | |||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||
| 102 | sub _disable { | ||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | my $pragma = shift; | ||||||||||||||||||||||||||||
|
Subroutine
_disable: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if ($warnings{"experimental::$pragma"}) { | ||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||
| 105 | 0 | warnings->import("experimental::$pragma"); | |||||||||||||||||||||||||||||
| 106 | 0 | ▶ | feature->unimport($pragma) if exists $features{$pragma}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | _disable(@{ $additional{$pragma} }) if $additional{$pragma}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||
| 109 | elsif ($features{$pragma}) { | ||||||||||||||||||||||||||||||
| 110 | 0 | feature->unimport($pragma); | |||||||||||||||||||||||||||||
| 111 | 0 | ▶ | _disable(@{ $additional{$pragma} }) if $additional{$pragma}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||
| 113 | elsif (not exists $min_version{$pragma}) { | ||||||||||||||||||||||||||||||
| 114 | 0 | carp "Can't disable unknown feature $pragma, ignoring"; | |||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||
| 118 | sub unimport { | ||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | my ($self, @pragmas) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
unimport: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||
| 121 | 0 | for my $pragma (@pragmas) { | |||||||||||||||||||||||||||||
| 122 | 0 | _disable($pragma); | |||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||
| 124 | 0 | return; | |||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||
| 127 | 1 | 1; | |||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||
| 129 | #ABSTRACT: Experimental features made easy | ||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||
| 131 | __END__ | ||||||||||||||||||||||||||||||