Subject: | Moo::HandleMoose::AuthorityHack::DESTROY crashing with 'perl -c file.pl' cleanup when Moose is not installed |
Date: | Fri, 27 Jul 2012 21:16:00 +0000 |
To: | "bug-Moo [...] rt.cpan.org" <bug-Moo [...] rt.cpan.org> |
From: | Ben Martin <Ben.Martin [...] mathworks.com> |
Hi,
I have found a pretty obscure problem with Moo when test compiling code when Moose and Devel::GlobalDestruction are not installed.
=== SUSPECTED BUG ===
In Moo/sification.pm, there is the following function:
sub Moo::HandleMoose::AuthorityHack::DESTROY {
unless (our $disarmed or Moo::_Utils::_in_global_destruction) {
require Moo::HandleMoose;
Moo::HandleMoose->import;
}
This is ultimately loading Moose, which fails to load.
I believe that the 'Moo::_Utils::_in_global_destruction' function fails to correctly detect global destruction when running under 'perl -c'.
=== PROPOSED FIX ===
Simply adding the line:
return unless $INC{"Moose.pm"};
to the start of the above sub fixes the issue for me. I don't know how that change impacts code when Moose is installed.
=== REPRODUCTION STEPS ===
On a (Debian 6) system with:
1. Moo installed (1. 000001 or 0.091007)
2. no Moose installed
3. no Devel::GlobalDestruction installed
5. Perl 5.8.8 or 5.10.1
Running the following script:
#!/usr/bin/perl -w
use Carp qw(confess);
BEGIN {
$SIG{qq{__DIE__}} = sub { confess(@_) };
}
use Moo;
exit 0;
works fine, but test compiling it with perl -c fails.
% perl -Iperlmod/CPAN/lib/perl5 -c moo_based_tool.pl
moo_based_tool.pl syntax OK
(in cleanup) Can't locate Class/MOP.pm in @INC (@INC contains: ...) at perlmod/CPAN/lib/perl5/Moo/HandleMoose.pm line 14 during global destruction.
at moo_based_tool.pl line 6
main::__ANON__('Can\'t locate Class/MOP.pm in @INC (@INC contains: ...') called at perlmod/CPAN/lib/perl5/Moo/HandleMoose.pm line 14
Moo::HandleMoose::inject_all() called at perlmod/CPAN/lib/perl5/Moo/HandleMoose.pm line 11
Moo::HandleMoose::import('Moo::HandleMoose') called at perlmod/CPAN/lib/perl5/Moo/sification.pm line 11
Moo::HandleMoose::AuthorityHack::DESTROY('Moo::HandleMoose::AuthorityHack=HASH(0x16f28f0)') called at Class/MOP.pm line 0
eval {...} called at Class/MOP.pm line 0
===
Thanks,
Ben Martin