Skip Menu |

This queue is for tickets about the Moo CPAN distribution.

Report information
The Basics
Id: 119118
Status: open
Priority: 0/
Queue: Moo

People
Owner: Nobody in particular
Requestors: peter [...] morch.com
Cc:
AdminCc:

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



Subject: Using Moo from a die handler can cause "Eval went very, very wrong:"
Date: Sat, 3 Dec 2016 16:29:47 +0100
To: bug-Moo [...] rt.cpan.org
From: Peter Valdemar Mørch <peter [...] morch.com>
I have this in Foo.pm: package Foo; use strict; use Moo; has 'attr' => ( is => 'ro', ); 1; And this in ./moosyntaxerror.pl: #!/usr/bin/perl -w use strict; use Foo; BEGIN { $SIG{__DIE__} = sub { Foo->new(); }; }; $nosuchvar; Without the Foo->new() line, I get this in the terminal as expected: londo@peter:~/junk> ./moosyntaxerror.pl Global symbol "$nosuchvar" requires explicit package name at ./ moosyntaxerror.pl line 9. Execution of ./moosyntaxerror.pl aborted due to compilation errors. With it, I get the unexpected: londo@peter:~/junk> ./moosyntaxerror.pl Eval went very, very wrong: { my $_QUOTED = ${$_[1]->{"\$_QUOTED"}}; my $_UNQUOTED = ${$_[1]->{"\$_UNQUOTED"}}; package Foo; no warnings 'closure'; sub new { ($_QUOTED,$_UNQUOTED) if 0; # BEGIN quote_sub PRELUDE package Foo; BEGIN { $^H = 2018; ${^WARNING_BITS} = "UUUUUUUUUUUUUUU\005"; %^H = ( ); } # END quote_sub PRELUDE my $invoker = CORE::shift(); my $class = CORE::ref($invoker) ? CORE::ref($invoker) : $invoker; if ($class ne "Foo") { if ($Moo::MAKERS{$class}) { if ($Moo::MAKERS{$class}{constructor}) { package Foo; return $invoker->SUPER::new(@_); } Moo->_constructor_maker_for($class); return $invoker->new(@_); } elsif ($INC{"Moose.pm"} and my $meta = Class::MOP::get_metaclass_by_name($class)) { return $meta->new_object( $class->can("BUILDARGS") ? $class->BUILDARGS(@_) : $class->Moo::Object::BUILDARGS(@_) ); } } my $args = scalar @_ == 1 ? CORE::ref $_[0] eq 'HASH' ? { %{ $_[0] } } : Carp::croak("Single parameters to new() must be a HASH ref" . " data => ". $_[0]) : @_ % 2 ? Carp::croak("The new() method for $class expects a hash reference or a" . " key/value list. You passed an odd number of arguments") : {@_} ; my $new = bless({}, $class);; (exists $args->{"attr"} and ($new->{"attr"} = $args->{"attr"})), return $new; } $$_UNQUOTED = \&new; } 1; BEGIN not safe after errors--compilation aborted at (eval 10) line 5. at /usr/share/perl5/Method/Generate/Constructor.pm line 170. londo@peter:~/junk> perl -MMoo -E 'say $Moo::VERSION' 2.002005 -- Peter Valdemar Mørch http://www.morch.com
Unfortunately I'm not seeing any possible way to resolve this. Moo uses code generation for large parts of its operation, and one of the primary design goals is to delay work for as long as possible. After the syntax error, code generation is no longer possible because perl will refuse to compile anything. The only solution I can really think of at this point is to detect this situation and throw a friendlier error message.
Subject: Re: [rt.cpan.org #119118] Using Moo from a die handler can cause "Eval went very, very wrong:"
Date: Thu, 15 Dec 2016 16:11:02 +0100
To: bug-Moo [...] rt.cpan.org
From: Peter Valdemar Mørch <peter [...] morch.com>
Fair enough. - It could be mentioned in the documentation. - One could improve the error, e.g. by checking if trivial compilation can be performed: e.g. if ($evalWentVeryVeryWrong) { eval '1'; if ($@) { die "Compilation is no longer possible"; } } Either way, this is a pathological case anyway, and I'm ok with this issue being closed. Peter On Thu, Dec 15, 2016 at 10:56 AM, Graham Knop via RT <bug-Moo@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=119118 > > > Unfortunately I'm not seeing any possible way to resolve this. Moo uses > code generation for large parts of its operation, and one of the primary > design goals is to delay work for as long as possible. After the syntax > error, code generation is no longer possible because perl will refuse to > compile anything. > > The only solution I can really think of at this point is to detect this > situation and throw a friendlier error message. >
-- Peter Valdemar Mørch http://www.morch.com