1

I would like to send a deprecation notice like

warnings::warnif( 'deprecated', 'function foo is deprecated' );

but I'd prefer to have it carp up so it reports to the caller and not where the actual warn is. Can I do this with carp somehow?

xenoterracide
  • 16,274
  • 24
  • 118
  • 243

1 Answers1

1

Have you tried it?

package Foo {
    sub bar {
        warnings::warnif(deprecated => 'Foo:bar is deprecated');
    }
}

use warnings;
# no warnings 'deprecated';    # <-- uncomment this to disable the warning
Foo::bar();                    # <-- this is line 9

This should say something like:

Foo::bar is deprecated at test.pl line 9.

In fact, looking at the warnings.pm source, it seems to use Carp.pm internally. Admittedly, the documentation for the warnings pragma itself could be clearer about this, but perllexwarn does make it pretty clear that this is how it's meant to be used.

Ilmari Karonen
  • 49,047
  • 9
  • 93
  • 153
  • yes I tried it.. the MOP is throwing off all my line numbers... apparently even now that I've set `@CARP_NOT` appropriately, so I didn't realize it was doing the right thing (or originally that `@CARP_NOT` would be getting obeyed ). now I guess I need to figure out what I'm missing since I put `__PACKAGE__` in `@CARP_NOT` but it still appears to be carping from package and not the test file. – xenoterracide Aug 01 '13 at 20:35