X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FObject.pm;h=6426dd644f777bf35484d5a2ee7811aac9ca1361;hb=4cf89c74c7bfc634dd2b3f884eb062ea7691e121;hp=409db5d6ba1ca6fcd2b150d4d888205e3480ab08;hpb=9922fa6fbb2dddabc660e9e70da543e977b2d2b3;p=gitmo%2FMoose.git diff --git a/lib/Moose/Object.pm b/lib/Moose/Object.pm index 409db5d..6426dd6 100644 --- a/lib/Moose/Object.pm +++ b/lib/Moose/Object.pm @@ -9,7 +9,7 @@ use if ( not our $__mx_is_compiled ), metaclass => 'Moose::Meta::Class'; use Carp 'confess'; -our $VERSION = '0.09'; +our $VERSION = '0.14'; our $AUTHORITY = 'cpan:STEVAN'; sub new { @@ -37,22 +37,34 @@ sub BUILDALL { return unless $_[0]->can('BUILD'); my ($self, $params) = @_; foreach my $method (reverse $self->meta->find_all_methods_by_name('BUILD')) { - $method->{code}->($self, $params); + $method->{code}->body->($self, $params); } } sub DEMOLISHALL { - # NOTE: we ask Perl if we even - # need to do this first, to avoid - # extra meta level calls - return unless $_[0]->can('DEMOLISH'); my $self = shift; foreach my $method ($self->meta->find_all_methods_by_name('DEMOLISH')) { - $method->{code}->($self); - } + $method->{code}->body->($self); + } } -sub DESTROY { goto &DEMOLISHALL } +sub DESTROY { + # NOTE: we ask Perl if we even + # need to do this first, to avoid + # extra meta level calls + return unless $_[0]->can('DEMOLISH'); + # if we have an exception here ... + if ($@) { + # localize the $@ ... + local $@; + # run DEMOLISHALL ourselves, ... + $_[0]->DEMOLISHALL; + # and return ... + return; + } + # otherwise it is normal destruction + $_[0]->DEMOLISHALL; +} # new does() methods will be created # as approiate see Moose::Meta::Role @@ -62,8 +74,9 @@ sub does { || confess "You much supply a role name to does()"; my $meta = $self->meta; foreach my $class ($meta->class_precedence_list) { + my $m = $meta->initialize($class); return 1 - if $meta->initialize($class)->does_role($role_name); + if $m->can('does_role') && $m->does_role($role_name); } return 0; } @@ -80,7 +93,7 @@ sub does { sub dump { my $self = shift; require Data::Dumper; - $Data::Dumper::Maxdepth = shift if @_; + local $Data::Dumper::Maxdepth = shift if @_; Data::Dumper::Dumper $self; }