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