bump version to 1.19
[gitmo/Moose.git] / lib / Moose / Meta / Method / Accessor / Native / String / replace.pm
CommitLineData
e7724627 1package Moose::Meta::Method::Accessor::Native::String::replace;
2
3use strict;
4use warnings;
5
88e88a7b 6use Moose::Util ();
7use Params::Util ();
8
245478d5 9our $VERSION = '1.19';
e7724627 10$VERSION = eval $VERSION;
11our $AUTHORITY = 'cpan:STEVAN';
12
8b9641b8 13use Moose::Role;
14
15with 'Moose::Meta::Method::Accessor::Native::Writer' => {
16 -excludes => [
17 qw(
18 _minimum_arguments
19 _maximum_arguments
20 _inline_check_arguments
21 _inline_optimized_set_new_value
22 )
23 ]
7f5ec80d 24 };
e7724627 25
26sub _minimum_arguments { 1 }
8b9641b8 27
e7724627 28sub _maximum_arguments { 2 }
29
30sub _inline_check_arguments {
31 my $self = shift;
32
33 return $self->_inline_throw_error(
34 q{'The first argument passed to replace must be a string or regexp reference'}
35 )
5394a1c7 36 . q{ unless Moose::Util::_STRINGLIKE0( $_[0] ) || Params::Util::_REGEX( $_[0] );}
e7724627 37 . $self->_inline_throw_error(
38 q{'The second argument passed to replace must be a string or code reference'}
5394a1c7 39 ) . q{ unless Moose::Util::_STRINGLIKE0( $_[1] ) || Params::Util::_CODELIKE( $_[1] );};
e7724627 40}
41
42sub _potential_value {
43 my ( $self, $slot_access ) = @_;
44
45 return "( do { my \$val = $slot_access; ref \$_[1] ? \$val =~ s/\$_[0]/\$_[1]->()/e : \$val =~ s/\$_[0]/\$_[1]/; \$val } )";
46}
47
e32b7489 48sub _inline_optimized_set_new_value {
49 my ( $self, $inv, $new, $slot_access ) = @_;
e7724627 50
51 return "if ( ref \$_[1] ) { $slot_access =~ s/\$_[0]/\$_[1]->()/e; } else { $slot_access =~ s/\$_[0]/\$_[1]/; }";
52}
53
8b9641b8 54no Moose::Role;
55
e7724627 561;