From: Stevan Little Date: Tue, 14 Nov 2006 16:59:02 +0000 (+0000) Subject: foo X-Git-Tag: 0_18_002~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1f7799268624a1daa3d84d8326f8f0bdc4ef8c75;p=gitmo%2FMoose.git foo --- diff --git a/benchmarks/immutable.pl b/benchmarks/immutable.pl index ac11614..3ff6f42 100644 --- a/benchmarks/immutable.pl +++ b/benchmarks/immutable.pl @@ -30,6 +30,16 @@ coerce 'Foo' has 'type_constraint' => (is => 'rw', isa => 'Foo'); has 'coercion' => (is => 'rw', isa => 'Foo', coerce => 1); + package Bar::Normal; + use Moose; + + extends 'Foo::Normal'; + + has 'default_w_type_constraint' => ( + is => 'rw', + isa => 'Int', + default => 10, + ); } { @@ -48,14 +58,27 @@ coerce 'Foo' # ... } - Foo::Immutable->meta->make_immutable(debug => 1); + Foo::Immutable->meta->make_immutable(debug => 0); + + package Bar::Immutable; + use Moose; + + extends 'Foo::Immutable'; + + has 'default_w_type_constraint' => ( + is => 'rw', + isa => 'Int', + default => 10, + ); + + Bar::Immutable->meta->make_immutable(debug => 0); } #__END__ my $foo = Foo->new; -cmpthese(500, +cmpthese(10_000, { 'normal' => sub { Foo::Normal->new( diff --git a/lib/Moose/Meta/Class.pm b/lib/Moose/Meta/Class.pm index a9f8915..ac40807 100644 --- a/lib/Moose/Meta/Class.pm +++ b/lib/Moose/Meta/Class.pm @@ -305,6 +305,7 @@ sub _process_inherited_attribute { ## ------------------------------------------------- use Moose::Meta::Method::Constructor; +use Moose::Meta::Method::Destructor; { # NOTE: @@ -342,6 +343,11 @@ use Moose::Meta::Method::Constructor; $IMMUTABLE_METACLASS->make_metaclass_immutable( $self, constructor_class => 'Moose::Meta::Method::Constructor', + destructor_class => 'Moose::Meta::Method::Destructor', + inline_destructor => 1, + # NOTE: + # no need to do this, + # Moose always does it inline_accessors => 0, @_, ) diff --git a/lib/Moose/Meta/Method/Constructor.pm b/lib/Moose/Meta/Method/Constructor.pm index ffccd44..3f7bfe6 100644 --- a/lib/Moose/Meta/Method/Constructor.pm +++ b/lib/Moose/Meta/Method/Constructor.pm @@ -71,7 +71,11 @@ sub intialize_body { # requires some adaption on the part of # the author, after all, nothing is free) my $source = 'sub {'; - $source .= "\n" . 'my $class = shift; '; + $source .= "\n" . 'my $class = shift;'; + + $source .= "\n" . 'return $class->Moose::Object::' . $self->options->{constructor_name} . '(@_)'; + $source .= "\n" . ' if $class ne \'' . $self->associated_metaclass->name . '\';'; + $source .= "\n" . 'my %params = (scalar @_ == 1) ? %{$_[0]} : @_;'; $source .= "\n" . 'my $instance = ' . $self->meta_instance->inline_create_instance('$class'); @@ -102,7 +106,7 @@ sub intialize_body { sub _generate_BUILDALL { my $self = shift; my @BUILD_calls; - foreach my $method ($self->associated_metaclass->find_all_methods_by_name('BUILD')) { + foreach my $method (reverse $self->associated_metaclass->find_all_methods_by_name('BUILD')) { push @BUILD_calls => '$instance->' . $method->{class} . '::BUILD(\%params)'; } return join "\n" => @BUILD_calls; diff --git a/lib/Moose/Object.pm b/lib/Moose/Object.pm index e754eb4..56fea9f 100644 --- a/lib/Moose/Object.pm +++ b/lib/Moose/Object.pm @@ -9,7 +9,7 @@ use metaclass 'Moose::Meta::Class'; use Carp 'confess'; -our $VERSION = '0.06'; +our $VERSION = '0.07'; sub new { my $class = shift; @@ -28,6 +28,7 @@ sub new { } 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); @@ -35,7 +36,8 @@ sub BUILDALL { } sub DEMOLISHALL { - my $self = shift; + return unless $_[0]->can('DEMOLISH'); + my $self = shift; foreach my $method ($self->meta->find_all_methods_by_name('DEMOLISH')) { $method->{code}->($self); } diff --git a/lib/Moose/Role.pm b/lib/Moose/Role.pm index 8a9d45b..af7dc87 100644 --- a/lib/Moose/Role.pm +++ b/lib/Moose/Role.pm @@ -12,7 +12,7 @@ use Sub::Name 'subname'; use Sub::Exporter; -our $VERSION = '0.05'; +our $VERSION = '0.06'; use Moose (); @@ -31,6 +31,7 @@ use Moose::Util::TypeConstraints; subtype $role => as 'Role' => where { $_->does($role) } + => optimize_as { blessed($_[0]) && $_[0]->can('does') && $_[0]->does($role) } unless find_type_constraint($role); my $meta;