Skip Menu |

This queue is for tickets about the Moo CPAN distribution.

Report information
The Basics
Id: 78617
Status: resolved
Priority: 0/
Queue: Moo

People
Owner: Nobody in particular
Requestors: Ben.Martin [...] mathworks.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 1.002000



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
On Fri Jul 27 17:16:19 2012, Ben.Martin@mathworks.com wrote: Show quoted text
> Hi, > > I have found a pretty obscure problem with Moo when test compiling > code when Moose and Devel::GlobalDestruction are not installed.
Note, the (in cleanup) error messages are actually just warnings. They do not alter the final $? nor any other program behavior on exit. Show quoted text
> I believe that the 'Moo::_Utils::_in_global_destruction' function > fails to correctly detect global destruction when running under 'perl > -c'.
Right... because END blocks (which non-XS D::GD relies on) are not invoked under -c. As per perlrun: -c causes Perl to check the syntax of the program and then exit without executing it. Actually, it will execute and "BEGIN", "UNITCHECK", or "CHECK" blocks and any "use" statements: these are considered as occurring outside the execution of your program. "INIT" and "END" blocks, however, will be skipped. I don't see a sane way of circumventing this limitation.
Thinking more about it I suppose we could examine $^C in a BEGIN and either forcefully attempt to load Moose, or set $disarm directly. Not sure which way is saner for pure syntax checking. I'd suspect a BEGIN { our $disarm = 1 if $^C } is sufficiently sane... Matt what do you think?
Subject: Re: [rt.cpan.org #78617] Moo::HandleMoose::AuthorityHack::DESTROY crashing with 'perl -c file.pl' cleanup when Moose is not installed
Date: Fri, 27 Jul 2012 22:40:46 +0000
To: "bug-Moo [...] rt.cpan.org" <bug-Moo [...] rt.cpan.org>
From: Ben Martin <Ben.Martin [...] mathworks.com>
Is it possible to differentiate between DESTROY being called on deletion and being overwritten? Peter Rabbitson via RT <bug-Moo@rt.cpan.org> wrote: <URL: https://rt.cpan.org/Ticket/Display.html?id=78617 > Thinking more about it I suppose we could examine $^C in a BEGIN and either forcefully attempt to load Moose, or set $disarm directly. Not sure which way is saner for pure syntax checking. I'd suspect a BEGIN { our $disarm = 1 if $^C } is sufficiently sane... Matt what do you think?
On Fri Jul 27 18:41:06 2012, Ben.Martin@mathworks.com wrote: Show quoted text
> Thinking more about it I suppose we could examine $^C in a BEGIN and > either forcefully attempt to load Moose, or set $disarm directly. Not > sure which way is saner for pure syntax checking. I'd suspect a > > BEGIN { our $disarm = 1 if $^C } is sufficiently sane... > > Matt what do you think?
CHECK {} is still called for -c (App::FatPacker::Trace uses that) so we could do it -there- - that way loading Moose during compilation will still do the expected thing. Note that I've unlined GlobalDestruction but if it's installed pure perl the bug probably still exists, so I'd still rather like to see a patch for this. Care to have a go, please?
Moo 1.002000 now requires Devel::GlobalDestruction 0.10, which fixes this issue.