This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
6c0ec79a2e9c445ac9999df2 failed to build from distclean - also tweak make_ext.pl
[perl5.git] / lib / deprecate.pm
CommitLineData
e76b2c0c 1package deprecate;
c0f08d2c 2use strict;
e76b2c0c
NC
3use warnings;
4our $VERSION = 0.01;
5
c0f08d2c
RB
6# our %Config can ignore %Config::Config, e.g. for testing
7our %Config;
8unless (%Config) { require Config; *Config = \%Config::Config; }
9
e76b2c0c
NC
10sub import {
11 my ($package, $file, $line) = caller;
12 my $expect_leaf = "$package.pm";
13 $expect_leaf =~ s!::!/!g;
14
15 foreach my $pair ([qw(sitearchexp archlibexp)],
16 [qw(sitelibexp privlibexp)]) {
17 my ($site, $priv) = @Config{@$pair};
18 # Just in case anyone managed to configure with trailing /s
19 s!/*$!!g foreach $site, $priv;
20
21 next if $site eq $priv;
22 if ("$priv/$expect_leaf" eq $file) {
d4be36a8
RB
23 my $call_depth=1;
24 my @caller;
25 while (@caller = caller $call_depth++) {
26 last if $caller[7] # use/require
27 and $caller[6] eq $expect_leaf; # the package file
28 }
29 unless (@caller) {
30 require Carp;
31 Carp::cluck(<<"EOM");
32Can't find use/require $expect_leaf in caller stack
33EOM
34 next;
35 }
36
e76b2c0c 37 # This is fragile, because it
d4be36a8
RB
38 # is directly poking in the internals of warnings.pm
39 my ($call_file, $call_line, $callers_bitmask) = @caller[1,2,9];
e76b2c0c
NC
40
41 if (defined $callers_bitmask
42 && (vec($callers_bitmask, $warnings::Offsets{deprecated}, 1)
43 || vec($callers_bitmask, $warnings::Offsets{all}, 1))) {
44 warn <<"EOM";
c0f08d2c 45$package will be removed from the Perl core distribution in the next major release. Please install it from CPAN. It is being used at $call_file, line $call_line.
e76b2c0c
NC
46EOM
47 }
48 return;
49 }
50 }
51}
52
531;