From: Florian Ragwitz Date: Thu, 4 Feb 2010 02:09:33 +0000 (+0100) Subject: Revert "add stubs for BUILD and DEMOLISH to Moose::Object" X-Git-Tag: 0.95~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=17819f173db6bbb010e4993291506834ccbd1e7b;p=gitmo%2FMoose.git Revert "add stubs for BUILD and DEMOLISH to Moose::Object" This reverts commit c310bfa05ac3defa413ad464e0c0350cab908995. Conflicts: Changes --- diff --git a/Changes b/Changes index db666d9..35d93b9 100644 --- a/Changes +++ b/Changes @@ -11,8 +11,6 @@ for, noteworthy changes. * Moose::Object::does no longer checks the entire inheritance tree, since Moose::Meta::Class::does_role already does this. (doy) - * Moose::Object now has stubs for BUILD and DEMOLISH, so they can be safely - wrapped in roles without needing to provide your own stubs. (doy) * Moose::Util::add_method_modifier (and subsequently the sugar functions Moose::before, Moose::after, and Moose::around) can now accept arrayrefs, with the same behavior as lists. Types other than arrayref and regexp result in an error. diff --git a/lib/Moose/Object.pm b/lib/Moose/Object.pm index 6aee996..1cd1f6a 100644 --- a/lib/Moose/Object.pm +++ b/lib/Moose/Object.pm @@ -48,16 +48,13 @@ sub BUILDALL { # NOTE: we ask Perl if we even # need to do this first, to avoid # extra meta level calls - return if $_[0]->can('BUILD') == \&BUILD; + return unless $_[0]->can('BUILD'); my ($self, $params) = @_; foreach my $method (reverse Class::MOP::class_of($self)->find_all_methods_by_name('BUILD')) { - next if $method->{class} eq __PACKAGE__; $method->{code}->execute($self, $params); } } -sub BUILD { } - sub DEMOLISHALL { my $self = shift; my ($in_global_destruction) = @_; @@ -65,7 +62,7 @@ sub DEMOLISHALL { # NOTE: we ask Perl if we even # need to do this first, to avoid # extra meta level calls - return if $self->can('DEMOLISH') == \&DEMOLISH; + return unless $self->can('DEMOLISH'); my @isa; if ( my $meta = Class::MOP::class_of($self ) ) { @@ -81,15 +78,12 @@ sub DEMOLISHALL { foreach my $class (@isa) { no strict 'refs'; - next if $class eq __PACKAGE__; my $demolish = *{"${class}::DEMOLISH"}{CODE}; $self->$demolish($in_global_destruction) if defined $demolish; } } -sub DEMOLISH { } - sub DESTROY { my $self = shift; diff --git a/t/030_roles/019_build.t b/t/030_roles/019_build.t index 41fb2cf..1dfc912 100644 --- a/t/030_roles/019_build.t +++ b/t/030_roles/019_build.t @@ -2,7 +2,6 @@ use strict; use warnings; use Test::More; -use Test::Moose; BEGIN { eval "use Test::Output;"; plan skip_all => "Test::Output is required for this test" if $@; @@ -12,8 +11,6 @@ BEGIN { # role: sub BUILD, after BUILD # continues to work to run code after object initialization, whether the class # has a BUILD method or not -# note: as of moose 0.95, this idiom is no longer necessary ('after BUILD' on -# its own is sufficient) -doy my @CALLS; @@ -54,35 +51,7 @@ do { with 'TestRole'; }; -do { - package TestRoleWithoutBUILD; - use Moose::Role; - - before BUILD => sub { push @CALLS, 'TestRoleWithoutBUILD::BUILD:before' }; - after BUILD => sub { push @CALLS, 'TestRoleWithoutBUILD::BUILD:after' }; -}; - -do { - package AnotherClassWithBUILD; - use Moose; - - ::stderr_is { - with 'TestRoleWithoutBUILD'; - } ''; - - sub BUILD { push @CALLS, 'AnotherClassWithBUILD::BUILD' } -}; - -do { - package AnotherClassWithoutBUILD; - use Moose; - - ::stderr_is { - with 'TestRoleWithoutBUILD'; - } ''; -}; - -with_immutable { +{ is_deeply([splice @CALLS], [], "no calls to BUILD yet"); ClassWithBUILD->new; @@ -101,21 +70,11 @@ with_immutable { 'TestRole::BUILD:after', ]); - AnotherClassWithBUILD->new; - - is_deeply([splice @CALLS], [ - 'TestRoleWithoutBUILD::BUILD:before', - 'AnotherClassWithBUILD::BUILD', - 'TestRoleWithoutBUILD::BUILD:after', - ]); - - AnotherClassWithoutBUILD->new; - - is_deeply([splice @CALLS], [ - 'TestRoleWithoutBUILD::BUILD:before', - 'TestRoleWithoutBUILD::BUILD:after', - ]); -} qw(ClassWithBUILD ClassWithoutBUILD - AnotherClassWithBUILD AnotherClassWithoutBUILD); + if (ClassWithBUILD->meta->is_mutable) { + ClassWithBUILD->meta->make_immutable; + ClassWithoutBUILD->meta->make_immutable; + redo; + } +} done_testing;