sub _inline_extra_init { }
+sub _eval_environment {
+ my $self = shift;
+
+ my @attrs = sort { $a->name cmp $b->name } $self->get_all_attributes;
+
+ my $defaults = [map { $_->default } @attrs];
+
+ return {
+ '$defaults' => \$defaults,
+ };
+}
+
sub get_meta_instance {
my $self = shift;
sub options { (shift)->{'options'} }
sub associated_metaclass { (shift)->{'associated_metaclass'} }
-## cached values ...
-
-sub _attributes {
- my $self = shift;
- $self->{'attributes'} ||= [
- sort { $a->name cmp $b->name }
- $self->associated_metaclass->get_all_attributes
- ]
-}
-
## method
sub _initialize_body {
sub _eval_environment {
my $self = shift;
- my $defaults = [map { $_->default } @{ $self->_attributes }];
- return {
- '$defaults' => \$defaults,
- };
+ return $self->associated_metaclass->_eval_environment;
}
sub _generate_constructor_method {
return @BUILD_calls;
}
+sub _eval_environment {
+ my $self = shift;
+
+ my @attrs = sort { $a->name cmp $b->name } $self->get_all_attributes;
+
+ my $triggers = [
+ map { $_->can('has_trigger') && $_->has_trigger ? $_->trigger : undef }
+ @attrs
+ ];
+
+ # We need to check if the attribute ->can('type_constraint')
+ # since we may be trying to immutabilize a Moose meta class,
+ # which in turn has attributes which are Class::MOP::Attribute
+ # objects, rather than Moose::Meta::Attribute. And
+ # Class::MOP::Attribute attributes have no type constraints.
+ # However we need to make sure we leave an undef value there
+ # because the inlined code is using the index of the attributes
+ # to determine where to find the type constraint
+
+ my @type_constraints = map {
+ $_->can('type_constraint') ? $_->type_constraint : undef
+ } @attrs;
+
+ my @type_constraint_bodies = map {
+ defined $_ ? $_->_compiled_type_constraint : undef;
+ } @type_constraints;
+
+ my @type_coercions = map {
+ defined $_ && $_->has_coercion
+ ? $_->coercion->_compiled_type_coercion
+ : undef
+ } @type_constraints;
+
+ my @type_constraint_messages = map {
+ defined $_
+ ? ($_->has_message ? $_->message : $_->_default_message)
+ : undef
+ } @type_constraints;
+
+ return {
+ %{ $self->SUPER::_eval_environment },
+ ((any { defined && $_->has_initializer } @attrs)
+ ? ('$attrs' => \[@attrs])
+ : ()),
+ '$triggers' => \$triggers,
+ '@type_coercions' => \@type_coercions,
+ '@type_constraint_bodies' => \@type_constraint_bodies,
+ '@type_constraint_messages' => \@type_constraint_messages,
+ ( map { defined($_) ? %{ $_->inline_environment } : () }
+ @type_constraints ),
+ # pretty sure this is only going to be closed over if you use a custom
+ # error class at this point, but we should still get rid of this
+ # at some point
+ '$meta' => \$self,
+ };
+}
+
sub superclasses {
my $self = shift;
my $supers = Data::OptList::mkopt(\@_);
$self->{'body'} = $self->_generate_constructor_method_inline;
}
-sub _eval_environment {
- my $self = shift;
-
- my $attrs = $self->_attributes;
-
- my $defaults = [map { $_->default } @$attrs];
- my $triggers = [
- map { $_->can('has_trigger') && $_->has_trigger ? $_->trigger : undef }
- @$attrs
- ];
-
- # We need to check if the attribute ->can('type_constraint')
- # since we may be trying to immutabilize a Moose meta class,
- # which in turn has attributes which are Class::MOP::Attribute
- # objects, rather than Moose::Meta::Attribute. And
- # Class::MOP::Attribute attributes have no type constraints.
- # However we need to make sure we leave an undef value there
- # because the inlined code is using the index of the attributes
- # to determine where to find the type constraint
-
- my @type_constraints = map {
- $_->can('type_constraint') ? $_->type_constraint : undef
- } @$attrs;
-
- my @type_constraint_bodies = map {
- defined $_ ? $_->_compiled_type_constraint : undef;
- } @type_constraints;
-
- my @type_coercions = map {
- defined $_ && $_->has_coercion
- ? $_->coercion->_compiled_type_coercion
- : undef
- } @type_constraints;
-
- my @type_constraint_messages = map {
- defined $_
- ? ($_->has_message ? $_->message : $_->_default_message)
- : undef
- } @type_constraints;
-
- return {
- ((any { defined && $_->has_initializer } @$attrs)
- ? ('$attrs' => \$attrs)
- : ()),
- '$defaults' => \$defaults,
- '$triggers' => \$triggers,
- '@type_coercions' => \@type_coercions,
- '@type_constraint_bodies' => \@type_constraint_bodies,
- '@type_constraint_messages' => \@type_constraint_messages,
- ( map { defined($_) ? %{ $_->inline_environment } : () }
- @type_constraints ),
- # pretty sure this is only going to be closed over if you use a custom
- # error class at this point, but we should still get rid of this
- # at some point
- '$meta' => \($self->associated_metaclass),
- };
-}
-
1;
# ABSTRACT: Method Meta Object for constructors
_inline_generate_instance _inline_params _inline_slot_initializers
_inline_init_attr_from_constructor _inline_init_attr_from_default
_generate_fallback_constructor
+ _eval_environment
construct_instance _construct_instance
construct_class_instance _construct_class_instance
clone_instance _clone_instance