1 package Moose::Meta::Method::Accessor::Native::String::replace;
7 $VERSION = eval $VERSION;
8 our $AUTHORITY = 'cpan:STEVAN';
12 with 'Moose::Meta::Method::Accessor::Native::Writer' => {
17 _inline_check_arguments
18 _inline_optimized_set_new_value
23 sub _minimum_arguments { 1 }
25 sub _maximum_arguments { 2 }
27 sub _inline_check_arguments {
30 return $self->_inline_throw_error(
31 q{'The first argument passed to replace must be a string or regexp reference'}
33 . q{ unless ! ref $_[0] || ref $_[0] eq 'Regexp';} . "\n"
34 . $self->_inline_throw_error(
35 q{'The second argument passed to replace must be a string or code reference'}
36 ) . q{ unless ! ref $_[1] || ref $_[1] eq 'CODE';};
39 sub _potential_value {
40 my ( $self, $slot_access ) = @_;
42 return "( do { my \$val = $slot_access; ref \$_[1] ? \$val =~ s/\$_[0]/\$_[1]->()/e : \$val =~ s/\$_[0]/\$_[1]/; \$val } )";
45 sub _inline_optimized_set_new_value {
46 my ( $self, $inv, $new, $slot_access ) = @_;
48 return "if ( ref \$_[1] ) { $slot_access =~ s/\$_[0]/\$_[1]->()/e; } else { $slot_access =~ s/\$_[0]/\$_[1]/; }";