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