【发布时间】:2022-11-16 18:34:56
【问题描述】:
我正在使用来自 @ikegami's post here 的 AUTOLOAD 示例。我的 RF::Component::Multi 模块的最近 CPAN testers report 说:
Bareword found where operator expected at .../RF/Component/Multi.pm line 102, near "s/^.*:://sr"
syntax error at .../RF/Component/Multi.pm line 102, near "s/^.*:://sr"
代码在下面和 GitHub 上的here。
- Perl 5.10 不喜欢什么?
- 是否有一个要求>5.10 的 Perl 特性隐藏在这里而我遗漏了? (我的 Perl 5.26.3 正在运行)
- 如果可以,是否可以使其更加向后兼容?如何?
- 如果不是,我在哪里可以找到版本以便我可以正确执行
use 5.xx?
- 我需要
use vars '$AUTOLOAD'吗?
# Thanks @ikegami:
# https://stackoverflow.com/a/74229589/14055985
sub AUTOLOAD
{
my $method_name = our $AUTOLOAD =~ s/^.*:://sr;
my $method = sub {
my $self = shift;
return [ map { $_->$method_name(@_) } @$self ];
};
{
no strict 'refs';
*$method_name = $method;
}
goto &$method;
}
【问题讨论】: