Add explicit return values for (almost) all native delegation mutating methods
[gitmo/Moose.git] / lib / Moose / Meta / Method / Accessor / Native / String / replace.pm
1 package Moose::Meta::Method::Accessor::Native::String::replace;
2
3 use strict;
4 use warnings;
5
6 use Moose::Util ();
7 use Params::Util ();
8
9 our $VERSION = '1.15';
10 $VERSION = eval $VERSION;
11 our $AUTHORITY = 'cpan:STEVAN';
12
13 use Moose::Role;
14
15 with '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     ]
24     };
25
26 sub _minimum_arguments { 1 }
27
28 sub _maximum_arguments { 2 }
29
30 sub _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         )
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] );};
40 }
41
42 sub _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
48 sub _inline_optimized_set_new_value {
49     my ( $self, $inv, $new, $slot_access ) = @_;
50
51     return "if ( ref \$_[1] ) { $slot_access =~ s/\$_[0]/\$_[1]->()/e; } else { $slot_access =~ s/\$_[0]/\$_[1]/; }";
52 }
53
54 no Moose::Role;
55
56 1;