Subject: | Delegation and Carping produces confusing results. |
Please see bug #109631 submitted against Moose. Moo has the same problem:
----------
$ cat moo-carping.pl
#!/usr/bin/perl
{
package BB;
use Moo;
use Carp;
sub method {
my ( $self ) = @_;
Carp::croak "AAA";
};
}
{
package AA;
use Moo;
has b => (
is => 'ro',
handles => [ 'method' ],
builder => '_build_b',
);
sub _build_b {
return BB->new();
};
}
my $a = AA->new();
$a->method();
$ perl ./moo-carping.pl
AAA at (eval 11) line 17.
----------
Such error location "(eval 11) line 17" is very confusing, especially for a newbie.
In case of Moose simple trick helps to fix the problem:
$Carp::Internal{ 'Moose::Meta::Method::Delegation' } = 1;
Unfortunately, I failed to make this work with Moo. Neither
$Carp::Internal{ 'Moo' } = 1;
nor
$Carp::Internal{ 'Sub::Defer' } = 1;
helps. I am not familiar with Moo (and Moose) internals, probably you know the module to declare "internal" for Carp?