use strict;
use warnings;
-our $VERSION = '0.73';
+our $VERSION = '0.75_01';
$VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
or $self->throw_error("Could not create writer for '${\$self->associated_attribute->name}' because $@ \n code: $code", error => $@, data => $code );
}
-sub generate_accessor_method_inline {
+sub _generate_accessor_method_inline {
my $self = $_[0];
my $attr = $self->associated_attribute;
my $attr_name = $attr->name;
. ' }');
}
-sub generate_writer_method_inline {
+sub _generate_writer_method_inline {
my $self = $_[0];
my $attr = $self->associated_attribute;
my $attr_name = $attr->name;
. ' }');
}
-sub generate_reader_method_inline {
+sub _generate_reader_method_inline {
my $self = $_[0];
my $attr = $self->associated_attribute;
my $attr_name = $attr->name;
return $attr->should_coerce;
}
-sub generate_reader_method { shift->generate_reader_method_inline(@_) }
-sub generate_writer_method { shift->generate_writer_method_inline(@_) }
-sub generate_accessor_method { shift->generate_accessor_method_inline(@_) }
-sub generate_predicate_method { shift->generate_predicate_method_inline(@_) }
-sub generate_clearer_method { shift->generate_clearer_method_inline(@_) }
+sub _generate_reader_method { shift->_generate_reader_method_inline(@_) }
+sub _generate_writer_method { shift->_generate_writer_method_inline(@_) }
+sub _generate_accessor_method { shift->_generate_accessor_method_inline(@_) }
+sub _generate_predicate_method { shift->_generate_predicate_method_inline(@_) }
+sub _generate_clearer_method { shift->_generate_clearer_method_inline(@_) }
sub _inline_pre_body { '' }
sub _inline_post_body { '' }
sub _inline_check_constraint {
my ($self, $value) = @_;
-
+
my $attr = $self->associated_attribute;
my $attr_name = $attr->name;
-
+
return '' unless $attr->has_type_constraint;
-
+
my $type_constraint_name = $attr->type_constraint->name;
qq{\$type_constraint->($value) || } . $self->_inline_throw_error(qq{"Attribute ($attr_name) does not pass the type constraint because: " . \$type_constraint_obj->get_message($value)}, "data => $value") . ";";
my ($self, $value) = @_;
my $attr = $self->associated_attribute;
-
+
return '' unless $attr->should_coerce;
return "$value = \$attr->type_constraint->coerce($value);";
}
my $attr = $self->associated_attribute;
my $attr_name = $attr->name;
-
+
return '' unless $attr->is_required;
return qq{(\@_ >= 2) || } . $self->_inline_throw_error(qq{"Attribute ($attr_name) is required, so cannot be set to undef"}) . ';' # defined $_[1] is not good enough
}
if ($attr->has_default || $attr->has_builder) {
if ($attr->has_default) {
$code .= ' my $default = $attr->default(' . $instance . ');'."\n";
- }
+ }
elsif ($attr->has_builder) {
$code .= ' my $default;'."\n".
' if(my $builder = '.$instance.'->can($attr->builder)){ '."\n".
$code .= $self->_inline_check_coercion('$default') . "\n";
$code .= $self->_inline_check_constraint('$default') . "\n";
$code .= ' ' . $self->_inline_init_slot($attr, $instance, $slot_access, '$default') . "\n";
- }
+ }
else {
$code .= ' ' . $self->_inline_init_slot($attr, $instance, $slot_access, 'undef') . "\n";
}
} else {
if ($attr->has_default) {
- $code .= ' ' . $self->_inline_init_slot($attr, $instance, $slot_access, ('$attr->default(' . $instance . ')')) . "\n";
- }
+ $code .= ' ' . $self->_inline_init_slot($attr, $instance, $slot_access, ('$attr->default(' . $instance . ')')) . "\n";
+ }
elsif ($attr->has_builder) {
- $code .= ' if (my $builder = '.$instance.'->can($attr->builder)) { ' . "\n"
- . ' ' . $self->_inline_init_slot($attr, $instance, $slot_access, ($instance . '->$builder'))
+ $code .= ' if (my $builder = '.$instance.'->can($attr->builder)) { ' . "\n"
+ . ' ' . $self->_inline_init_slot($attr, $instance, $slot_access, ($instance . '->$builder'))
. "\n } else {\n"
. ' ' . $self->_inline_throw_error(q{sprintf "%s does not support builder method '%s' for attribute '%s'", ref(} . $instance . ') || '.$instance.', $attr->builder, $attr->name')
. ';'. "\n }";
- }
+ }
else {
$code .= ' ' . $self->_inline_init_slot($attr, $instance, $slot_access, 'undef') . "\n";
}
}
else {
return ($slot_access . ' = ' . $value . ';');
- }
+ }
}
sub _inline_store {
my ($self, $instance, $value) = @_;
my $attr = $self->associated_attribute;
-
+
my $mi = $attr->associated_class->get_meta_instance;
-
+
my $code = $mi->inline_set_slot_value($instance, $attr->slots, $value) . ";";
$code .= $mi->inline_weaken_slot_value($instance, $attr->slots, $value) . ";"
if $attr->is_weak_ref;
sub _inline_get {
my ($self, $instance) = @_;
my $attr = $self->associated_attribute;
-
+
my $mi = $attr->associated_class->get_meta_instance;
return $mi->inline_get_slot_value($instance, $attr->slots);
sub _inline_access {
my ($self, $instance) = @_;
my $attr = $self->associated_attribute;
-
+
my $mi = $attr->associated_class->get_meta_instance;
return $mi->inline_slot_access($instance, $attr->slots);
sub _inline_has {
my ($self, $instance) = @_;
my $attr = $self->associated_attribute;
-
+
my $mi = $attr->associated_class->get_meta_instance;
return $mi->inline_is_slot_initialized($instance, $attr->slots);