Subject: | Generated accessors metamethod objects should probably have "original_package" pointing to the role that defined them |
In the event that you have
package SomeRole; use Moose::Role; has 'foo' => ( ... ); package Consumer; with 'SomeRole';
Trying to determine which package provided the generated accessor 'foo' proves unintuitive:
Consumer->meta->get_method('foo')->original_package_name()
reports that 'foo' comes from the 'Consumer' class, not, as you would expect, the role that defined it, 'SomeRole'
Attached is a simple test that tests for this problem, with the 4 common accessor types.
Subject: | moose_inheritance.pl |
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
BEGIN {
package Some::Role;
use Moose::Role;
has 'rubbish' => (
reader => '_rubbish_reader',
writer => '_rubbish_writer',
predicate => '_rubbish_predicate',
clearer => '_rubbish_clearer',
builder => '_build_rubbish',
required => 1
);
sub _build_rubbish {
1
}
no Moose::Role;
}
BEGIN {
package Child;
use Moose;
with 'Some::Role';
__PACKAGE__->meta->make_immutable;
no Moose;
$INC{'Child.pm'} = 1;
}
my $meta = Child->meta();
use Scalar::Util qw( blessed );
for my $method_name ( sort $meta->get_method_list ) {
my $method = $meta->get_method($method_name);
next if $method_name =~ /^(DESTROY|meta|new)$/;
isnt( $method->original_package_name,
'Child', "$method_name should not come from Child" );
}
done_testing;