""(Dagfinn Ilmari Mannsåker)" via RT" <bug-Moo@rt.cpan.org> writes:
Show quoted text> Queue: Moo
> Ticket <URL:
https://rt.cpan.org/Ticket/Display.html?id=101111 >
>
> "Ilmari Ikonen via RT" <bug-Moo@rt.cpan.org> writes:
>
>> I am using Moo-1.006001 in Perl 5.20.1. The following code fails with
>> a long stack trace related to Moo::ification:
>
> Thanks for reporting this. Here's a minimal case that reproduces what I
> can only guess (since you didn't include the error output) is the error:
>
> { package RA; use Moose::Role; }
> { package CA; use Moose; }
> { package CB; use Moo; extends 'CA'; }
>
> RA->meta->consumers;
>
> Note that no class needs to consume the role, but the Moo class needs to
> extend a Moose class.
Even more minimally:
require Method::Generate::Constructor;
require Moo::HandleMoose;
Moo::HandleMoose::inject_real_metaclass_for('Method::Generate::Constructor');
This is because Method::Generate::Constructor has manually defined
accessor methods for the attributes before doing 'use Moo'. This causes
Moo to not consider them method, so the
local @{_getstash($name)}{keys %methods};
in Moo::HandleMoose::inject_real_metaclass_for() fails to hide them from
Moose::Meta::Attribute::_process_accessors().
One possible fix would be to delete the accessors from the not_methods
list at the end of bootstrapping Method::Generate::Constructor:
diff --git a/lib/Method/Generate/Constructor.pm b/lib/Method/Generate/Constructor.pm
index 6828357..a8046bd 100644
--- a/lib/Method/Generate/Constructor.pm
+++ b/lib/Method/Generate/Constructor.pm
@@ -205,8 +205,7 @@ sub new {
my $class = shift;
bless $class->BUILDARGS(@_), $class;
}
-Moo->_constructor_maker_for(__PACKAGE__)
-->register_attribute_specs(
+my %attr = (
attribute_specs => {
is => 'ro',
reader => 'all_attribute_specs',
@@ -217,5 +216,12 @@ Moo->_constructor_maker_for(__PACKAGE__)
subconstructor_handler => { is => 'ro' },
package => { is => 'bare' },
);
+Moo->_constructor_maker_for(__PACKAGE__)
+->register_attribute_specs(%attr);
+for my $name (keys %attr) {
+ if (my $meth = __PACKAGE__->can($attr{$name}{reader}||$name)) {
+ delete ${$Moo::MAKERS{+__PACKAGE__}{not_methods}}{$meth};
+ }
+}
1;
--
"I use RMS as a guide in the same way that a boat captain would use
a lighthouse. It's good to know where it is, but you generally
don't want to find yourself in the same spot." - Tollef Fog Heen