You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Perl中添加no warnings qw(experimental::signatures)仍触发签名警告

问题根因

你设置no warnings qw(experimental::signatures)的位置在use Moose之前,而Moose加载时会默认重新导入warnings编译指示,重置了你之前针对警告的自定义配置,所以你对实验性签名的警告屏蔽规则没有生效。

解决方法

你只需要调整代码顺序,把禁用实验性签名警告的语句放到use Moose之后即可:

package Foo;
use strict;
use warnings;
use feature qw(signatures);

use Moose;
no warnings qw(experimental::signatures); # 移到Moose加载之后

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

sub boom ($self, $stuff) {
    print "$stuff\n";
}
1;

如果想要更简洁的写法,也可以直接使用experimental模块,一行代码同时完成开启签名特性、关闭对应实验警告的操作,该语句同样建议放在use Moose之后:

use experimental 'signatures';

内容的提问来源于stack exchange,提问作者Todd

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 04:15:00