1 package Moose::Meta::Method::Accessor::Native::String::Writer;
7 $VERSION = eval $VERSION;
8 our $AUTHORITY = 'cpan:STEVAN';
11 Moose::Meta::Method::Accessor::Native::String
12 Moose::Meta::Method::Accessor::Native::Writer
15 sub _new_value {'$_[0]'}
17 sub _inline_copy_value {
18 my ( $self, $potential_ref ) = @_;
20 return q{} unless $self->_value_needs_copy;
22 my $code = "my \$potential = ${$potential_ref};";
24 ${$potential_ref} = '$potential';
29 sub _value_needs_copy {
32 return $self->_constraint_must_be_checked;
36 my ( $self, $new_value, $potential_value ) = @_;
38 return q{} unless $self->_constraint_must_be_checked;
40 return $self->_inline_check_coercion($potential_value) . "\n"
41 . $self->_inline_check_constraint($potential_value);
44 sub _constraint_must_be_checked {
47 my $attr = $self->associated_attribute;
49 return $attr->has_type_constraint
50 && ( $attr->type_constraint->name ne 'Str'
51 || ( $attr->should_coerce && $attr->type_constraint->has_coercion ) );
54 sub _inline_check_coercion {
55 my ( $self, $value ) = @_;
57 my $attr = $self->associated_attribute;
60 unless $attr->should_coerce && $attr->type_constraint->has_coercion;
62 # We want to break the aliasing in @_ in case the coercion tries to make a
63 # destructive change to an array member.
64 return '@_ = @{ $attr->type_constraint->coerce($value) };';