有没有办法在调用者中为重载运算符抑制特定警告?
背景: 我正在研究一个重载<=
并>=
实现一种声明性域特定语言的模块。不管这是否是一个好主意,这些运算符在 void 上下文中使用时会抛出“在 void 上下文中无用”的警告。就像是:
package Boundary;
use strict;
use overload ('<=' => \&set_min, '>=' => \&set_max);
sub new { my ($class, $min, $max) = @_; bless [ $min, $max ], $class; }
sub set_min { my $self = shift; $self->[0] = shift; }
sub set_max { my $self = shift; $self->[1] = shift; }
package main;
# user code
use warnings;
my $bound = Boundary->new();
$bound >= 1; # Useless use of numeric ge (>=) in void context at ...
$bound <= 10; # Useless use of numeric le (>=) in void context at ...
有没有办法仅针对重载调用抑制警告,而调用者不必显式禁用“无效”警告?