default => 0
));
-InstanceCountingClass->meta->add_before_method_modifier('construct_instance' => sub {
+InstanceCountingClass->meta->add_before_method_modifier('_construct_instance' => sub {
my ($class) = @_;
$class->{'count'}++;
});
initialization hash. For instance, if we have an C<init_arg> 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<init_arg> is explicitly set to C<undef>, the
}
# 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
# 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
# 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();
use strict;
use warnings;
-use Test::More tests => 260;
+use Test::More tests => 262;
use Test::Exception;
use Class::MOP;
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
methods => {
'new' => sub {
my $class = shift;
- my $instance = $class->meta->construct_instance(@_);
+ my $instance = $class->meta->new_object(@_);
bless $instance => $class;
},
'clear' => sub {
sub new {
my $class = shift;
- bless $class->meta->construct_instance(@_) => $class;
+ bless $class->meta->new_object(@_) => $class;
}
sub clear {
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);
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');
sub new {
my $class = shift;
- bless $class->meta->construct_instance(@_) => $class;
+ bless $class->meta->new_object(@_) => $class;
}
}