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