1

这是warnings::warnif( 'deprecated' ... ) with carp 的后续问题?.

这是我在 Github 上来自 Business::Cyber​​Source 的代码片段

注意:上一个答案(在上一个问题中),并添加 of@CARP_NOT已经证明warnings::warnif使用carp. 我尝试直接替换鲤鱼,行为完全相同。

our @CARP_NOT = ( __PACKAGE__, qw( Class::MOP::Method::Wrapped ) );

around BUILDARGS => sub {
  my $orig  = shift;
  my $class = shift;

  my $args = $class->$orig( @_ );

  if ( exists $args->{username} ) {
    warnings::warnif('deprecated',
        '`username` is deprecated, use `user` instead'
    );

但是当我调用这段代码时

use strict;
use warnings;
use Test::More;

use Business::CyberSource::Client;
my $class = 'Business::CyberSource::Client';

my $client
= new_ok( $class => [{
    username   => $ENV{PERL_BUSINESS_CYBERSOURCE_USERNAME} || 'test',
    password   => $ENV{PERL_BUSINESS_CYBERSOURCE_PASSWORD} || 'test',
    production => 0,
}]);

错误仍然是从错误的地方报告的(尽管至少不是来自Class::MOP::Method::Wrapped

t/new-client.t .. `username` is deprecated, use `user` instead at constructor Business::CyberSource::Client::new (defined at /home/xenoterracide/Documents/Business-CyberSource/lib/Business/CyberSource/Client.pm line 314) line 6.

如何从测试文件中的正确行号生成此报告?->new(注意:如果我直接调用而不是使用,行为不会改变new_ok

4

0 回答 0