use warnings;
use Carp qw( croak );
+use List::MoreUtils qw( any );
use Params::Util qw( _HASH );
use Sub::Install;
my $deprecated_at = shift;
my $ignore = shift;
- my %ignore = map { $_ => 1 } @{ $ignore || [] };
+ my %ignore = map { $_ => 1 } grep { !ref } @{ $ignore || [] };
+ my @ignore_res = grep {ref} @{ $ignore || [] };
my %warned;
my ( $package, undef, undef, $sub ) = caller(1);
- # We want to start two levels back, since we already looked
- # one level back and found an internal package.
my $skipped = 1;
+
if ( keys %ignore ) {
- while ( defined $package && $ignore{$package} ) {
- $package = caller($skipped++);
+ while ( defined $package
+ && ( $ignore{$package} || any { $package =~ $_ } @ignore_res )
+ ) {
+ $package = caller( $skipped++ );
}
}
you don't want to deprecate an entire subroutine, just a certain usage.
You can also provide an optional array reference in the C<-ignore>
-parameter. This is a list of package names to ignore when looking at the stack
-to figure out what code used the deprecated feature. This should be packages
-in your distribution that can appear on the call stack when a deprecated
-feature is used.
+parameter.
+
+The values to be ignored can be package names or regular expressions (made
+with C<qr//>). Use this to ignore packages in your distribution that can
+appear on the call stack when a deprecated feature is used.
As part of the import process, C<Package::DeprecationManager> will export two
subroutines into its caller. It provides an C<import()> sub for the caller and a
}
{
+ package Dep3;
+
+ use Package::DeprecationManager -deprecations => {
+ 'baz' => '1.00',
+ },
+ -ignore => [ qr/My::Package[12]/ ];
+
+ sub baz {
+ deprecated('baz is deprecated');
+ }
+}
+
+{
package My::Package1;
sub foo { Dep::foo() }
sub bar { Dep2::bar() }
+ sub baz { Dep3::baz() }
}
{
sub foo { My::Package1::foo() }
sub bar { My::Package1::bar() }
+ sub baz { My::Package1::baz() }
}
{
package My::Baz;
+ ::warning_like{ My::Package1::bar() }
+ qr/^bar is deprecated at t.basic\.t line \d+/,
+ 'deprecation warning for call to My::Package1::bar()';
+
::warning_like{ My::Package2::foo() }
qr/^foo is deprecated at t.basic\.t line \d+/,
'deprecation warning for call to My::Package2::foo()';
- ::warning_like{ My::Package1::bar() }
- qr/^bar is deprecated at t.basic\.t line \d+/,
- 'deprecation warning for call to My::Package1::bar()';
+ ::warning_like{ My::Package1::baz() }
+ qr/^baz is deprecated at t.basic\.t line \d+/,
+ 'deprecation warning for call to My::Package2::foo()';
}
{