+ - mangle constructor meta-method on inflation so make_immutable works
- fix possible infinite loop caused by subconstructor code
0.009_016 - 2012-04-12
require Class::MOP;
inject_fake_metaclass_for($_) for grep $_ ne 'Moo::Object', keys %Moo::MAKERS;
inject_fake_metaclass_for($_) for keys %Moo::Role::INFO;
+ require Moose::Meta::Method::Constructor;
+ @Moo::HandleMoose::FakeConstructor::ISA = 'Moose::Meta::Method::Constructor';
}
sub inject_fake_metaclass_for {
our %DID_INJECT;
+{
+ package Moo::HandleMoose::FakeConstructor;
+
+ sub _uninlined_body { \&Moose::Object::new }
+}
+
+
sub inject_real_metaclass_for {
my ($name) = @_;
return Class::MOP::get_metaclass_by_name($name) if $DID_INJECT{$name};
$method->{body} = $name->can($method->name);
}
}
+ bless(
+ $meta->find_method_by_name('new'),
+ 'Moo::HandleMoose::FakeConstructor',
+ );
}
$meta->add_role(Class::MOP::class_of($_))
for keys %{$Role::Tiny::APPLIED_TO{$name}};
--- /dev/null
+use strictures 1;
+use Test::More;
+
+{
+ package Tower1;
+
+ use Moo;
+
+ has 'attr1' => (is => 'ro', required => 1);
+
+ package Tower2;
+
+ use Moose;
+
+ extends 'Tower1';
+
+ has 'attr2' => (is => 'ro', required => 1);
+
+ __PACKAGE__->meta->make_immutable;
+
+ package Tower3;
+
+ use Moo;
+
+ extends 'Tower2';
+
+ has 'attr3' => (is => 'ro', required => 1);
+
+ package Tower4;
+
+ use Moose;
+
+ extends 'Tower3';
+
+ has 'attr4' => (is => 'ro', required => 1);
+
+ __PACKAGE__->meta->make_immutable;
+}
+
+foreach my $num (1..4) {
+ my $class = "Tower${num}";
+ my @attrs = map "attr$_", 1..$num;
+ my %args = map +($_ => "${_}_value"), @attrs;
+ my $obj = $class->new(%args);
+ is($obj->{$_}, "${_}_value", "Attribute $_ ok for $class") for @attrs;
+}
+
+done_testing;