1 package Moose::Meta::Method::Accessor::Native::String::replace;
10 $VERSION = eval $VERSION;
11 our $AUTHORITY = 'cpan:STEVAN';
15 with 'Moose::Meta::Method::Accessor::Native::Writer' => {
20 _inline_check_arguments
21 _inline_optimized_set_new_value
26 sub _minimum_arguments { 1 }
28 sub _maximum_arguments { 2 }
30 sub _inline_check_arguments {
33 return $self->_inline_throw_error(
34 q{'The first argument passed to replace must be a string or regexp reference'}
36 . q{ unless Moose::Util::_STRINGLIKE0( $_[0] ) || Params::Util::_REGEX( $_[0] );}
37 . $self->_inline_throw_error(
38 q{'The second argument passed to replace must be a string or code reference'}
39 ) . q{ unless Moose::Util::_STRINGLIKE0( $_[1] ) || Params::Util::_CODELIKE( $_[1] );};
42 sub _potential_value {
43 my ( $self, $slot_access ) = @_;
45 return "( do { my \$val = $slot_access; ref \$_[1] ? \$val =~ s/\$_[0]/\$_[1]->()/e : \$val =~ s/\$_[0]/\$_[1]/; \$val } )";
48 sub _inline_optimized_set_new_value {
49 my ( $self, $inv, $new, $slot_access ) = @_;
51 return "if ( ref \$_[1] ) { $slot_access =~ s/\$_[0]/\$_[1]->()/e; } else { $slot_access =~ s/\$_[0]/\$_[1]/; }";