$class->throw_error("Unknown accessor type '$type'");
}
- # XXX: an anon class can be a runtime created class
- if ($attribute->is_lazy || $class->is_anon_class) {
+ if ($attribute->is_lazy) {
my $value;
if (defined $builder){
my %args = (@_ == 1) ? %{ $_[0] } : @_;
+ my $instance;
+
if($applicant->isa('Mouse::Meta::Class')){ # Application::ToClass
$args{_to} = 'class';
}
}
else{ # Appplication::ToInstance
$args{_to} = 'instance';
+ $instance = $applicant;
- my $metaclass = (Mouse::Util::class_of($applicant) || 'Mouse::Meta::Class')->create_anon_class(
- superclasses => [ref $applicant],
+ $applicant = (Mouse::Util::class_of($instance) || 'Mouse::Meta::Class')->create_anon_class(
+ superclasses => [ref $instance],
cache => 1,
);
- bless $applicant, $metaclass->name; # rebless
-
- $applicant = $metaclass;
}
if($args{alias} && !exists $args{-alias}){
$self->_apply_methods($applicant, \%args);
$self->_apply_modifiers($applicant, \%args);
$self->_append_roles($applicant, \%args);
+
+
+ if(defined $instance){ # Application::ToInstance
+ # rebless instance
+ bless $instance, $applicant->name;
+ $applicant->_initialize_object($instance, $instance);
+ }
+
return;
}