my $simple = "${me}->{${name_str}} = ${value}";
if ($spec->{weak_ref}) {
- require Scalar::Util;
+ { local $@; require Scalar::Util; }
# Perl < 5.8.3 can't weaken refs to readonly vars
# (e.g. string constants). This *can* be solved by:
eval { Scalar::Util::weaken($simple); 1 } or do {
if( \$@ =~ /Modification of a read-only value attempted/) {
- require Carp;
+ { local $@; require Carp; }
Carp::croak( sprintf (
'Reference to readonly value in "%s" can not be weakened on Perl < 5.8.3',
$name_str,
$body .= ' my $new = '.$self->construction_string.";\n";
$body .= $self->_assign_new($spec);
if ($into->can('BUILD')) {
- require Method::Generate::BuildAll;
+ { local $@; require Method::Generate::BuildAll; }
$body .= Method::Generate::BuildAll->new->buildall_body_for(
$into, '$new', '$args'
);
@{*{_getglob("${target}::ISA")}{ARRAY}} = @_;
};
*{_getglob("${target}::with")} = sub {
- require Moo::Role;
+ { local $@; require Moo::Role; }
die "Only one role supported at a time by with" if @_ > 1;
Moo::Role->apply_role_to_package($target, $_[0]);
};
*{_getglob("${target}::has")} = sub {
my ($name, %spec) = @_;
($MAKERS{$target}{accessor} ||= do {
- require Method::Generate::Accessor;
+ { local $@; require Method::Generate::Accessor; }
Method::Generate::Accessor->new
})->generate_method($target, $name, \%spec);
$class->_constructor_maker_for($target)
};
foreach my $type (qw(before after around)) {
*{_getglob "${target}::${type}"} = sub {
- require Class::Method::Modifiers;
+ { local $@; require Class::Method::Modifiers; }
_install_modifier($target, $type, @_);
};
}
{
no strict 'refs';
@{"${target}::ISA"} = do {
- require Moo::Object; ('Moo::Object');
+ {; local $@; require Moo::Object; } ('Moo::Object');
} unless @{"${target}::ISA"};
}
}
my ($class, $target, $select_super) = @_;
return unless $MAKERS{$target};
$MAKERS{$target}{constructor} ||= do {
- require Method::Generate::Constructor;
- require Sub::Defer;
+ {
+ local $@;
+ require Method::Generate::Constructor;
+ require Sub::Defer;
+ }
my ($moo_constructor, $con);
if ($select_super && $MAKERS{$select_super}) {
->new(
package => $target,
accessor_generator => do {
- require Method::Generate::Accessor;
+ { local $@; require Method::Generate::Accessor; }
Method::Generate::Accessor->new;
},
construction_string => (
use strictures 1;
our %NO_BUILD;
+our %NO_DEMOLISH;
our $BUILD_MAKER;
our $DEMOLISH_MAKER;
sub BUILDALL {
my $self = shift;
$self->${\(($BUILD_MAKER ||= do {
- require Method::Generate::BuildAll;
+ { local $@; require Method::Generate::BuildAll; }
Method::Generate::BuildAll->new
})->generate_method(ref($self)))}(@_);
}
+sub DEMOLISHALL {
+ my $self = shift;
+ $self->${\(($DEMOLISH_MAKER ||= do {
+ { local $@; require Method::Generate::DemolishAll; }
+ Method::Generate::DemolishAll->new
+ })->generate_method(ref($self)))}(@_);
+}
+
sub DESTROY {
- my $self = shift;
+ my $self = shift;
- return unless $self->can('DEMOLISH'); # short circuit
+ my $class = ref($self);
- require Moo::_Utils;
+ $NO_DEMOLISH{$class} = !$class->can('DEMOLISH')
+ unless exists $NO_DEMOLISH{$class};
- my $e = do {
- local $?;
- local $@;
- eval {
- # DEMOLISHALL
+ return if $NO_DEMOLISH{$class};
- $self->DEMOLISHALL($Moo::_Utils::_in_global_destruction);
- };
- $@;
+ my $e = do {
+ local $?;
+ local $@;
+ require Moo::_Utils;
+ eval {
+ $self->DEMOLISHALL($Moo::_Utils::_in_global_destruction);
};
+ $@;
+ };
- no warnings 'misc';
- die $e if $e; # rethrow
-}
-
-sub DEMOLISHALL {
- my $self = shift;
- $self->${\(($DEMOLISH_MAKER ||= do {
- require Method::Generate::DemolishAll;
- Method::Generate::DemolishAll->new
- })->generate_method(ref($self)))}(@_);
+ no warnings 'misc';
+ die $e if $e; # rethrow
}
sub does {
- require Role::Tiny;
+ { local $@; require Role::Tiny; }
{ no warnings 'redefine'; *does = \&Role::Tiny::does_role }
goto &Role::Tiny::does_role;
}
*{_getglob "${target}::has"} = sub {
my ($name, %spec) = @_;
($INFO{$target}{accessor_maker} ||= do {
- require Method::Generate::Accessor;
+ { local $@; require Method::Generate::Accessor; }
Method::Generate::Accessor->new
})->generate_method($target, $name, \%spec);
$INFO{$target}{attributes}{$name} = \%spec;
return $new_name if $Role::Tiny::COMPOSED{class}{$new_name};
- require Sub::Quote;
+ { local $@; require Sub::Quote; }
$me->SUPER::create_class_with_roles($superclass, @roles);
my ($into, $type, $name, $code) = @_;
if (my $to_modify = $into->can($name)) { # CMM will throw for us if not
- require Sub::Defer;
+ { local $@; require Sub::Defer; }
Sub::Defer::undefer_sub($to_modify);
}
# can't just ->can('can') because a sub-package Foo::Bar::Baz
# creates a 'Baz::' key in Foo::Bar's symbol table
return 1 if grep !/::$/, keys %{_getstash($_[0])||{}};
- require "${proto}.pm";
+ { local $@; require "${proto}.pm"; }
return 1;
}
sub _maybe_load_module {
return $MAYBE_LOADED{$_[0]} if exists $MAYBE_LOADED{$_[0]};
(my $proto = $_[0]) =~ s/::/\//g;
+ local $@;
if (eval { require "${proto}.pm"; 1 }) {
$MAYBE_LOADED{$_[0]} = 1;
} else {
our $_in_global_destruction = 0;
END { $_in_global_destruction = 1 }
+sub STANDARD_DESTROY {
+ my $self = shift;
+
+ my $e = do {
+ local $?;
+ local $@;
+ eval {
+ $self->DEMOLISHALL($_in_global_destruction);
+ };
+ $@;
+ };
+
+ no warnings 'misc';
+ die $e if $e; # rethrow
+}
+
1;
package Moo::_mro;
+local $@;
+
if ($] >= 5.010) {
require mro;
} else {
# can't just ->can('can') because a sub-package Foo::Bar::Baz
# creates a 'Baz::' key in Foo::Bar's symbol table
return 1 if grep !/::$/, keys %{_getstash($_[0])||{}};
- require "${proto}.pm";
+ { local $@; require "${proto}.pm"; }
return 1;
}
# install before/after/around subs
foreach my $type (qw(before after around)) {
*{_getglob "${target}::${type}"} = sub {
- require Class::Method::Modifiers;
+ { local $@; require Class::Method::Modifiers; }
push @{$INFO{$target}{modifiers}||=[]}, [ $type => @_ ];
};
}
}
if ($] >= 5.010) {
- require mro;
+ { local $@; require mro; }
} else {
- require MRO::Compat;
+ { local $@; require MRO::Compat; }
}
my @composable = map $me->_composable_package_for($_), reverse @roles;
) {
push @mod_base, "sub ${modified} { shift->next::method(\@_) }";
}
- eval(my $code = join "\n", "package ${base_name};", @mod_base);
- die "Evaling failed: $@\nTrying to eval:\n${code}" if $@;
+ {
+ local $@;
+ eval(my $code = join "\n", "package ${base_name};", @mod_base);
+ die "Evaling failed: $@\nTrying to eval:\n${code}" if $@;
+ }
$me->_install_modifiers($composed_name, $modifiers);
$COMPOSED{role}{$composed_name} = 1;
return $composed_name;
$ENV{SUB_QUOTE_DEBUG} && warn $assembled_code;
}
$assembled_code .= "\n1;";
- unless (_clean_eval $assembled_code, \@assembled_captures) {
- die "Eval went very, very wrong:\n\n${debug_code}\n\n$@";
+ {
+ local $@;
+ unless (_clean_eval $assembled_code, \@assembled_captures) {
+ die "Eval went very, very wrong:\n\n${debug_code}\n\n$@";
+ }
}
$ENV{SUB_QUOTE_DEBUG} && warn $debug_code;
%QUOTE_OUTSTANDING = ();