Subject: | Delegation and Carping produces confusing results. |
Please consider example:
----------
#!/usr/bin/perl
{
package BB;
use Moose;
use Carp;
sub method {
my ( $self ) = @_;
Carp::croak "AAA";
};
}
{
package AA;
use Moose;
has b => (
is => 'ro',
handles => [ 'method' ],
builder => '_build_b',
);
sub _build_b {
return BB->new();
};
}
my $a = AA->new();
$a->method();
----------
Note: class AA delegates method to attribute b of class BB. Being run, the program prints:
----------
$ perl ./pod-simple-test.pl
AAA at .../lib/perl5/x86_64-linux-thread-multi/Moose/Meta/Method/Delegation.pm line 110.
----------
Note: problem location is shown somewhere in Moose guts. It is quite consufing, especially for a newbie.
I do not say it is a problem of Moose exclusively. The problem is located somewhere between Moose and Carp.
In my little experiment, adding
our @CARP_NOT = qw{ Moose::Meta::Method::Delegation };
to the class BB (!) helps to workaround the problem.
$Carp::Internal{ 'Moose::Meta::Method::Delegation' } = 1;
also helps.
Probably Moose could add Moose::Meta::Method::Delegation to class' @CARP_NOT automatically, or set %Carp::Internal to avoid this confusing behavior?