but surprisingly it doesn't - this emits warnings. Why is that?
My guess is that this has the same scope problems that no warnings 'deprecated' has.
It seems the -X of the shebang-line takes effect even though you explicitly invoke perl on the command line. Is that so?
From DESCRIPTION in perlrun:
The #! line is always examined for switches as the line is being parsed.
Finally I would be interested if there is a way to globally disable specifically the deprecation warnings only.
I'm hoping someone can offer up a more elegant solution, as the following seems a little fragile/hackish. In order to filter out deprecation warnings, I've put in a BEGIN block with a second internal block with a localized WARN handler. Since perl compiles each module at most one time, this catches the emitted warnings on the first compile. The regular expression then filters out any newline-delimited portion of the emitted warnings that contain the word deprecated. Note that swapping from a require to a use will make the following code fail to catch the warnings, at least on my machine.
BEGIN {
my $initial_warnings = "";
{
local $SIG{__WARN__} = sub{$initial_warnings .= $_[0]};
require Foo;
}
$initial_warnings =~ s/^.*deprecated.*$ \n?//xmg;
warn $initial_warnings if $initial_warnings;
}
use Foo;