From: Yuval Kogman Date: Wed, 13 Aug 2008 21:19:18 +0000 (+0000) Subject: allow forcing of constructor inlining X-Git-Tag: 0_64_01~27 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6c2f6b5c3b6f9cf9ab4399f3a5f85b90f12cca4f;p=gitmo%2FClass-MOP.git allow forcing of constructor inlining --- diff --git a/lib/Class/MOP.pm b/lib/Class/MOP.pm index 46a7e2c..65df897 100644 --- a/lib/Class/MOP.pm +++ b/lib/Class/MOP.pm @@ -714,12 +714,9 @@ undef Class::MOP::Instance->meta->{_package_cache_flag}; # no actual benefits. $_->meta->make_immutable( - ( $_->can("_new") ? ( - inline_constructor => 1, - constructor_name => "_new", - ) : ( - inline_constructor => 0, - ) ), + inline_constructor => 1, + replace_constructor => 1, + constructor_name => "_new", inline_accessors => 0, ) for qw/ Class::MOP::Package diff --git a/lib/Class/MOP/Immutable.pm b/lib/Class/MOP/Immutable.pm index 09ed6a5..2318346 100644 --- a/lib/Class/MOP/Immutable.pm +++ b/lib/Class/MOP/Immutable.pm @@ -127,7 +127,7 @@ sub make_metaclass_immutable { package_name => $metaclass->name, name => $options{constructor_name} ) - ) unless $metaclass->has_method($options{constructor_name}); + ) if $options{replace_constructor} or !$metaclass->has_method($options{constructor_name}); } if ($options{inline_destructor}) { diff --git a/lib/Class/MOP/Object.pm b/lib/Class/MOP/Object.pm index 1b7d2c5..defd47d 100644 --- a/lib/Class/MOP/Object.pm +++ b/lib/Class/MOP/Object.pm @@ -16,6 +16,11 @@ sub meta { Class::MOP::Class->initialize(blessed($_[0]) || $_[0]); } +sub _new { + my ( $class, @args ) = @_; + Class::MOP::Class->initialize($class)->new_object(@args); +} + # RANT: # Cmon, how many times have you written # the following code while debugging: diff --git a/t/010_self_introspection.t b/t/010_self_introspection.t index 6591501..11d96a1 100644 --- a/t/010_self_introspection.t +++ b/t/010_self_introspection.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 224; +use Test::More tests => 230; use Test::Exception; BEGIN { @@ -28,6 +28,7 @@ my $class_mop_module_meta = Class::MOP::Module->meta(); isa_ok($class_mop_module_meta, 'Class::MOP::Module'); my @class_mop_package_methods = qw( + _new initialize @@ -41,11 +42,13 @@ my @class_mop_package_methods = qw( ); my @class_mop_module_methods = qw( + _new version authority identifier ); my @class_mop_class_methods = qw( + _new initialize reinitialize create