From: Dave Rolsky Date: Sun, 5 Apr 2009 16:06:40 +0000 (-0500) Subject: make CMOP::Class->construct_instance private X-Git-Tag: 0.80_01~14 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d69fb6b34cf37d63bbed4d941ad809539299e218;p=gitmo%2FClass-MOP.git make CMOP::Class->construct_instance private --- diff --git a/examples/InstanceCountingClass.pod b/examples/InstanceCountingClass.pod index 3cf3eb3..b28fef8 100644 --- a/examples/InstanceCountingClass.pod +++ b/examples/InstanceCountingClass.pod @@ -14,7 +14,7 @@ InstanceCountingClass->meta->add_attribute('count' => ( default => 0 )); -InstanceCountingClass->meta->add_before_method_modifier('construct_instance' => sub { +InstanceCountingClass->meta->add_before_method_modifier('_construct_instance' => sub { my ($class) = @_; $class->{'count'}++; }); diff --git a/lib/Class/MOP/Attribute.pm b/lib/Class/MOP/Attribute.pm index 9340f35..802d4d0 100644 --- a/lib/Class/MOP/Attribute.pm +++ b/lib/Class/MOP/Attribute.pm @@ -501,7 +501,7 @@ This is a string value representing the expected key in an initialization hash. For instance, if we have an C value of C<-foo>, then the following code will Just Work. - MyClass->meta->construct_instance( -foo => 'Hello There' ); + MyClass->meta->new_object( -foo => 'Hello There' ); If an init_arg is not assigned, it will automatically use the attribute's name. If C is explicitly set to C, the diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index ef1d1a1..7ea9965 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -45,7 +45,7 @@ sub construct_class_instance { } # NOTE: (meta-circularity) -# this is a special form of &construct_instance +# this is a special form of _construct_instance # (see below), which is used to construct class # meta-object instances for any Class::MOP::* # class. All other classes will use the more @@ -86,7 +86,7 @@ sub _construct_class_instance { # it is safe to use meta here because # class will always be a subclass of # Class::MOP::Class, which defines meta - $meta = $class->meta->construct_instance($options) + $meta = $class->meta->_construct_instance($options) } # and check the metaclass compatibility @@ -338,10 +338,16 @@ sub new_object { # which will deal with the singletons return $class->_construct_class_instance(@_) if $class->name->isa('Class::MOP::Class'); - return $class->construct_instance(@_); + return $class->_construct_instance(@_); } sub construct_instance { + warn 'The construct_instance method has been made private.' + . " The public version is deprecated and will be removed in a future release.\n"; + shift->_construct_instance; +} + +sub _construct_instance { my $class = shift; my $params = @_ == 1 ? $_[0] : {@_}; my $meta_instance = $class->get_meta_instance(); diff --git a/t/010_self_introspection.t b/t/010_self_introspection.t index 6fc43ec..1e35255 100644 --- a/t/010_self_introspection.t +++ b/t/010_self_introspection.t @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 260; +use Test::More tests => 262; use Test::Exception; use Class::MOP; @@ -60,7 +60,7 @@ my @class_mop_class_methods = qw( instance_metaclass get_meta_instance create_meta_instance _create_meta_instance new_object clone_object - construct_instance + construct_instance _construct_instance construct_class_instance _construct_class_instance clone_instance _clone_instance rebless_instance rebless_instance_away diff --git a/t/011_create_class.t b/t/011_create_class.t index 839a8d9..a0f6fe3 100644 --- a/t/011_create_class.t +++ b/t/011_create_class.t @@ -21,7 +21,7 @@ my $Point = Class::MOP::Class->create('Point' => ( methods => { 'new' => sub { my $class = shift; - my $instance = $class->meta->construct_instance(@_); + my $instance = $class->meta->new_object(@_); bless $instance => $class; }, 'clear' => sub { diff --git a/t/013_add_attribute_alternate.t b/t/013_add_attribute_alternate.t index 1bb0f03..f133d3e 100644 --- a/t/013_add_attribute_alternate.t +++ b/t/013_add_attribute_alternate.t @@ -22,7 +22,7 @@ use Class::MOP; sub new { my $class = shift; - bless $class->meta->construct_instance(@_) => $class; + bless $class->meta->new_object(@_) => $class; } sub clear { diff --git a/t/024_attribute_initializer.t b/t/024_attribute_initializer.t index 46f6c31..328ff7c 100644 --- a/t/024_attribute_initializer.t +++ b/t/024_attribute_initializer.t @@ -34,7 +34,7 @@ This checks that the initializer is used to set the initial value. can_ok('Foo', 'get_bar'); can_ok('Foo', 'set_bar'); -my $foo = Foo->meta->construct_instance(bar => 10); +my $foo = Foo->meta->new_object(bar => 10); is($foo->get_bar, 20, "... initial argument was doubled as expected"); $foo->set_bar(30); diff --git a/t/072_immutable_w_constructors.t b/t/072_immutable_w_constructors.t index abed7a7..7ef79f0 100644 --- a/t/072_immutable_w_constructors.t +++ b/t/072_immutable_w_constructors.t @@ -228,14 +228,14 @@ BEGIN {use Class::MOP;use Class::MOP::Immutable; ok(!Baz->meta->has_method('new'), '... no constructor was made'); { - my $baz = Baz->meta->construct_instance; + my $baz = Baz->meta->new_object; isa_ok($baz, 'Bar'); is($baz->bar, 'BAR', '... got the right default value'); is($baz->baz, 'BAZ', '... got the right default value'); } { - my $baz = Baz->meta->construct_instance(bar => 'BAZ!', baz => 'BAR!', bah => 'BAH!'); + my $baz = Baz->meta->new_object(bar => 'BAZ!', baz => 'BAR!', bah => 'BAH!'); isa_ok($baz, 'Baz'); is($baz->bar, 'BAZ!', '... got the right parameter value'); is($baz->baz, 'BAR!', '... got the right parameter value'); diff --git a/t/106_LazyClass_test.t b/t/106_LazyClass_test.t index a941c40..94c50fb 100644 --- a/t/106_LazyClass_test.t +++ b/t/106_LazyClass_test.t @@ -33,7 +33,7 @@ BEGIN {use Class::MOP; sub new { my $class = shift; - bless $class->meta->construct_instance(@_) => $class; + bless $class->meta->new_object(@_) => $class; } }