}
sub initialize_instance_slot {
- my ($self, $class, $instance, $params) = @_;
+ my ($self, $instance, $params) = @_;
my $init_arg = $self->init_arg();
# try to fetch the init arg from the %params ...
my $val;
}
}
+sub _gen_required_arg {
+ my ( $self, $attr_name, $arg ) = @_;
+ return sprintf 'defined(%s) || confess "Attribute (%s) is required, so cannot be set to undef";', $arg, $attr_name;
+}
+
+sub _gen_coerce {
+ my ( $self, $attr_name, $arg );
+ return sprintf '%s->type->type_constraint->coercion->coerce(%s)', $self->_gen_invocant, $arg;
+}
+
sub generate_accessor_method {
my ($self, $attr_name) = @_;
my $value_name = $self->should_coerce ? '$val' : '$_[1]';
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
-=cut
\ No newline at end of file
+=cut
sub construct_instance {
my ($class, %params) = @_;
- my $instance = $params{'__INSTANCE__'} || {};
+ my $instance = $params{'__INSTANCE__'} || $class->get_meta_instance->create_instance();
foreach my $attr ($class->compute_all_applicable_attributes()) {
- $attr->initialize_instance_slot($class, $instance, \%params)
+ $attr->initialize_instance_slot($instance, \%params)
}
return $instance;
}
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
-=cut
\ No newline at end of file
+=cut