}
sub new_object {
- my $self = shift;
+ my $meta = shift;
my %args = (@_ == 1 ? %{$_[0]} : @_);
- my $object = bless {}, $self->name;
+ my $object = bless {}, $meta->name;
- $self->_initialize_object($object, \%args);
+ $meta->_initialize_object($object, \%args);
+ # BUILDALL
+ if( $object->can('BUILD') ) {
+ for my $class (reverse $meta->linearized_isa) {
+ my $build = Mouse::Util::get_code_ref($class, 'BUILD')
+ || next;
+
+ $object->$build(\%args);
+ }
+ }
return $object;
}
my $args = $class->BUILDARGS(@_);
my $meta = Mouse::Meta::Class->initialize($class);
- my $self = $meta->new_object($args);
-
- # BUILDALL
- if( $self->can('BUILD') ) {
- for my $class (reverse $meta->linearized_isa) {
- my $build = Mouse::Util::get_code_ref($class, 'BUILD')
- || next;
-
- $self->$build($args);
- }
- }
-
- return $self;
+ return $meta->new_object($args);
}
sub DESTROY {
#!/usr/bin/env perl
use strict;
use warnings;
-use Test::More tests => 9;
+use Test::More;
use Test::Mouse;
my @called;
$child->BUILDALL({});
is_deeply([splice @called], ["Class::BUILD", "Child::BUILD"], 'BUILDALL');
+
+ $child = Child->meta->new_object();
+ is_deeply([splice @called], ["Class::BUILD", "Child::BUILD"], 'new_object calls BUILDALL');
}, qw(Class Child);
+done_testing;
RETVAL = mouse_instance_create(aTHX_ MOUSE_xc_stash(xc));
mouse_class_initialize_object(aTHX_ meta, RETVAL, args, FALSE);
+ mouse_buildall(aTHX_ xc, RETVAL, args); /* BUILDALL */
}
OUTPUT:
RETVAL
/* new_object */
RETVAL = mouse_instance_create(aTHX_ MOUSE_xc_stash(xc));
mouse_class_initialize_object(aTHX_ meta, RETVAL, (HV*)SvRV(args), FALSE);
-
- mouse_buildall(aTHX_ xc, RETVAL, args);
+ mouse_buildall(aTHX_ xc, RETVAL, args); /* BUILDALL */
}
OUTPUT:
RETVAL