Subject: | Module::Refresh Errors on Immutable Classes with Roles |
Date: | Sun, 25 Jul 2010 19:19:43 -0700 |
To: | bug-Class-MOP [...] rt.cpan.org |
From: | Aran Deltac <bluefeet [...] gmail.com> |
I've tested this on a recent build of Moose/Class::MOP. Here's my test
case:
test.pl:
---------------------------------------
use strict;
use warnings;
use Foo;
use Module::Refresh;
my $foo = Foo->new();
foreach (1..10) {
Module::Refresh->refresh;
$foo->do();
sleep 10;
}
Foo.pm:
---------------------------------------
package Foo;
use Moose;
with 'Bar';
sub do {
print "Do\n";
}
__PACKAGE__->meta->make_immutable;
1;
Bar.pm:
---------------------------------------
package Bar;
use Moose::Role;
1;
Now, start up test.pl and then modify the print() line in Foo.pm, notice the
errors. I get this:
Do
Subroutine do redefined at Foo.pm line 6.
The 'Class::MOP::Class::Immutable::Moose::Meta::Class=HASH(0x9cc0350)'
method cannot be called on an immutable instance at
/vcm/home/lib/site_perl/i386-linux-thread-multi/Class/MOP/Class/Immutable/Trait.pm
line 32
Class::MOP::Class::Immutable::Trait::_immutable_cannot_call('Class::MOP::Class::Immutable::Moose::Meta::Class=HASH(0x9cc0350)')
called at /vcm/home/lib/site_perl/Moose/Meta/Class/Immutable/Trait.pm line
14
Class::MOP::Class:::around('CODE(0x99f538c)',
'Class::MOP::Class::Immutable::Moose::Meta::Class=HASH(0x9cc0350)',
'Moose::Meta::Role=HASH(0x9ce61d0)') called at
/vcm/home/lib/site_perl/i386-linux-thread-multi/Class/MOP/Method/Wrapped.pm
line 159
Class::MOP::Method::Wrapped::__ANON__('Class::MOP::Class::Immutable::Moose::Meta::Class=HASH(0x9cc0350)',
'Moose::Meta::Role=HASH(0x9ce61d0)') called at
/vcm/home/lib/site_perl/i386-linux-thread-multi/Class/MOP/Method/Wrapped.pm
line 89
Class::MOP::Class::Immutable::Moose::Meta::Class::add_role('Class::MOP::Class::Immutable::Moose::Meta::Class=HASH(0x9cc0350)',
'Moose::Meta::Role=HASH(0x9ce61d0)') called at
/vcm/home/lib/site_perl/Moose/Meta/Role/Application/ToClass.pm line 33
Moose::Meta::Role::Application::ToClass::apply('Moose::Meta::Role::Application::ToClass=HASH(0x9708fb4)',
'Moose::Meta::Role=HASH(0x9ce61d0)',
'Class::MOP::Class::Immutable::Moose::Meta::Class=HASH(0x9cc0350)') called
at /vcm/home/lib/site_perl/Moose/Meta/Role.pm line 395
Moose::Meta::Role::apply('Moose::Meta::Role=HASH(0x9ce61d0)',
'Class::MOP::Class::Immutable::Moose::Meta::Class=HASH(0x9cc0350)') called
at /vcm/home/lib/site_perl/Moose/Util.pm line 121
Moose::Util::_apply_all_roles('Class::MOP::Class::Immutable::Moose::Meta::Class=HASH(0x9cc0350)',
'undef', 'Bar') called at /vcm/home/lib/site_perl/Moose/Util.pm line 84
Moose::Util::apply_all_roles('Class::MOP::Class::Immutable::Moose::Meta::Class=HASH(0x9cc0350)',
'Bar') called at /vcm/home/lib/site_perl/Moose.pm line 57
Moose::with('Class::MOP::Class::Immutable::Moose::Meta::Class=HASH(0x9cc0350)',
'Bar') called at /vcm/home/lib/site_perl/Moose/Exporter.pm line 288
Moose::with('Bar') called at Foo.pm line 4
require Foo.pm called at /vcm/home/lib/site_perl/Module/Refresh.pm
line 119
eval {...} called at /vcm/home/lib/site_perl/Module/Refresh.pm line
119
(unknown)('Module::Refresh', 'Foo.pm') called at
/vcm/home/lib/site_perl/Module/Refresh.pm line 96
(unknown)('Module::Refresh', 'Foo.pm') called at
/vcm/home/lib/site_perl/Module/Refresh.pm line 79
(unknown)('Module::Refresh') called at test.pl line 10
Compilation failed in require at /vcm/home/lib/site_perl/Module/Refresh.pm
line 119.
D2o
D2o
D2o
D2o
D2o
D2o
D2o
D2o
D2o
Now, if I remove the `with 'Bar'` line OR the
`__PACKAGE__->meta->make_immutable` line the error goes away and everything
works as expected.
I'm a bit at a loss as to what the issue is. For now I'm just going to
remove the make_immutable lines during development.
Aran