Carp reporting from the wrong location with @CARP_NOT (Moose and Method Modifiers)

点点圈 提交于 2019-12-11 14:15:58

问题


This is a followup question to warnings::warnif( 'deprecated' … ) with carp?.

here's a snippet of my code from Business::CyberSource on Github

note: the previous answer (in the previous question), and adding of @CARP_NOT have demonstrated that warnings::warnif uses carp. I attempted to substitute carp directly, the behavior was exactly the same.

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'
    );

But when I call this code

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,
}]);

The error is still reported from the wrong place (though at least not from 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.

How can I make this report from the correct line number in the test file? (note: behavior did not change if I called ->new directly instead of using new_ok

来源:https://stackoverflow.com/questions/18004716/carp-reporting-from-the-wrong-location-with-carp-not-moose-and-method-modifier

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!