X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoo%2FObject.pm;h=fb7415d0cffbf4f176223fe7fb8f87260b66b98a;hb=59812c87b1b00da1098f22c77e02db83ff594f22;hp=06a86f970779377287d865edd24dda35277ceb23;hpb=56ffe19d51215674fb162c30ba9c5dc1951402c5;p=gitmo%2FRole-Tiny.git diff --git a/lib/Moo/Object.pm b/lib/Moo/Object.pm index 06a86f9..fb7415d 100644 --- a/lib/Moo/Object.pm +++ b/lib/Moo/Object.pm @@ -3,6 +3,7 @@ package Moo::Object; use strictures 1; our %NO_BUILD; +our %NO_DEMOLISH; our $BUILD_MAKER; our $DEMOLISH_MAKER; @@ -41,43 +42,45 @@ sub BUILDARGS { 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; }