| 1 | package Package::DeprecationManager; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | our $VERSION = '0.17'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use List::Util 1.33 qw( any ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Package::Stash; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Params::Util qw( _HASH0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Sub::Install; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use Sub::Name qw( subname ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | sub import { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 5 | ▶ | shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 5 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | croak | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 'You must provide a hash reference -deprecations parameter when importing Package::DeprecationManager' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 5 | ▶ | unless $args{-deprecations} && _HASH0( $args{-deprecations} ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$args{"-deprecations"} and &_HASH0($args{"-deprecations"})
MC/DC50%1/2
$args{"-deprecations"} and &_HASH0($args{"-deprecations"})
$args{"-deprecations"}
&_HASH0($args{"-deprecations"})
Truth table66%2/3
A and B
A= $args{"-deprecations"}B= &_HASH0($args{"-deprecations"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 4 | my %registry; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 4 | my $caller = caller(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 4 | my $orig_import = $caller->can('import'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 4 | my $import = _build_import( \%registry, $orig_import ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | my $warn | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 4 | = _build_warn( \%registry, $args{-deprecations}, $args{-ignore} ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # We need to remove this to prevent a 'subroutine redefined' warning. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 4 | ▶ | if ($orig_import) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 4 | Package::Stash->new($caller)->remove_symbol('&import'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | Sub::Install::install_sub( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 4 | code => subname( $caller . '::import', $import ), | |||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | into => $caller, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | as => 'import', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 4 | Sub::Install::install_sub( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | code => subname( $caller . '::deprecated', $warn ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | into => $caller, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | as => 'deprecated', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | sub _build_import { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 4 | ▶ | my $registry = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_import: called CC=1 SCAR=0.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 4 | my $orig_import = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | return sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 4 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=6 SCAR=18.4
Subroutine
__ANON__: called CC=6 SCAR=18.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 4 | my @args; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | my $api_version; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | ## no critic (ControlStructures::ProhibitCStyleForLoops) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 4 | ▶ | for ( my $i = 0; $i < @_; $i++ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 2 | ▶ | if ( $_[$i] eq '-api_version' || $_[$i] eq '-compatible' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%3/6
$_[$i] eq "-api_version" or $_[$i] eq "-compatible"
$_[$i] eq "-api_version" or $_[$i] eq "-compatible"
MC/DC0%0/2
$_[$i] eq "-api_version" or $_[$i] eq "-compatible"
$_[$i] eq "-api_version"
$_[$i] eq "-compatible"
MC/DC50%1/2
$_[$i] eq "-api_version" or $_[$i] eq "-compatible"
$_[$i] eq "-api_version"
$_[$i] eq "-compatible"
Truth table33%1/3
A or B
A= $_[$i] eq "-api_version"B= $_[$i] eq "-compatible"
Truth table66%2/3
A or B
A= $_[$i] eq "-api_version"B= $_[$i] eq "-compatible"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | $api_version = $_[ ++$i ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | push @args, $_[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | ## use critic | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 4 | my $caller = caller(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 4 | ▶ | $registry->{$caller} = $api_version | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | if defined $api_version; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 4 | ▶ | if ($orig_import) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 4 | @_ = ( $class, @args ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 4 | goto &{$orig_import}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 4 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | sub _build_warn { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 4 | ▶ | my $registry = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_warn: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 4 | my $deprecated_at = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 4 | my $ignore = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 4 | ▶ | my %ignore = map { $_ => 1 } grep { !ref } @{ $ignore || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 4 | ▶ | my @ignore_res = grep {ref} @{ $ignore || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 4 | my %warned; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | return sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 24 | ▶ | my %args = @_ < 2 ? ( message => shift ) : @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deprecated: called CC=15 SCAR=27.1
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 24 | my ( $package, undef, undef, $sub ) = caller(1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 24 | my $skipped = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 24 | ▶ | if ( @ignore_res || keys %ignore ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@ignore_res or keys %ignore
MC/DC100%2/2
@ignore_res or keys %ignore
@ignore_res
keys %ignore
Truth table100%3/3
A or B
A= @ignore_resB= keys %ignore
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 7 | ▶ | while ( defined $package | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $package and $ignore{$package} || &any(sub {
$package =~ /$_/;
}
, @ignore_res)
$ignore{$package} or &any(sub {
$package =~ /$_/;
}
, @ignore_res)
MC/DC33%1/3
defined $package and $ignore{$package} || &any(sub {
$package =~ /$_/;
}
, @ignore_res)
defined $package
$ignore{$package}
&any(sub {
$package =~ /$_/;
}
, @ignore_res)
Truth table50%2/4
A and B or C
A= defined $packageB= $ignore{$package}C= &any(sub {
$package =~ /$_/;
}
, @ignore_res)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 8 | ▶ | && ( $ignore{$package} || any { $package =~ $_ } @ignore_res ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 18 | $package = caller( $skipped++ ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 24 | ▶ | $package = 'unknown package' unless defined $package; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 24 | ▶ | unless ( defined $args{feature} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 23 | $args{feature} = $sub; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 24 | my $compat_version = $registry->{$package}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 24 | my $at = $deprecated_at->{ $args{feature} }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 24 | ▶ | if defined $compat_version | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $compat_version and defined $deprecated_at and $compat_version lt $at
defined $compat_version and defined $deprecated_at
MC/DC66%2/3
defined $compat_version and defined $deprecated_at and $compat_version lt $at
defined $compat_version
defined $deprecated_at
$compat_version lt $at
Truth table75%3/4
A and B and C
A= defined $compat_versionB= defined $deprecated_atC= $compat_version lt $at
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | && defined $deprecated_at | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | && $compat_version lt $at; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 19 | my $msg; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 19 | ▶ | if ( defined $args{message} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 17 | $msg = $args{message}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 2 | $msg = "$args{feature} has been deprecated"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 2 | ▶ | $msg .= " since version $at" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | if defined $at; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 19 | ▶ | return if $warned{$package}{ $args{feature} }{$msg}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 11 | $warned{$package}{ $args{feature} }{$msg} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | # We skip at least two levels. One for this anon sub, and one for the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | # sub calling it. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 11 | local $Carp::CarpLevel = $Carp::CarpLevel + $skipped; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 11 | Carp::cluck($msg); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 4 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # ABSTRACT: Manage deprecation warnings for your distribution | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||