尽管“没有警告 qw(experimental::signatures)”,签名仍会生成警告消息

Tod*_*odd 5 perl moose

创建了一个包并想要使用签名。

package Foo;
use strict;
use warnings;
use feature qw(signatures);
no warnings qw(experimental::signatures);

use Moose;

has bar => ( is => 'ro', isa => 'Str' );

sub boom ($self, $stuff) {
    print "$stuff\n";
}
1;
Run Code Online (Sandbox Code Playgroud)

测试一下:

perl -wc Foo.pm
The signatures feature is experimental at ./Foo.pm line 11.
Run Code Online (Sandbox Code Playgroud)

这是怎么回事?我认为“无警告”编译指示会抑制该警告!

Tod*_*odd 7

问题是该use Moose;行重新启用所有警告。

解决方法是将其移至no warnings qw(experimental::signatures)该线下方use Moose;

例如:

use Moose;
no warnings qw(experimental::signatures);
Run Code Online (Sandbox Code Playgroud)