1 package Moose::Meta::Method::Accessor::Native::String::substr;
10 with 'Moose::Meta::Method::Accessor::Native::Reader',
11 'Moose::Meta::Method::Accessor::Native::Writer';
13 sub _generate_method {
17 my $slot_access = $self->_get_value($inv);
21 'my ' . $inv . ' = shift;',
22 $self->_inline_curried_arguments,
23 'if (@_ == 1 || @_ == 2) {',
24 $self->_inline_reader_core($inv, $slot_access),
27 $self->_inline_writer_core($inv, $slot_access),
30 $self->_inline_check_argument_count,
36 sub _minimum_arguments { 1 }
37 sub _maximum_arguments { 3 }
39 sub _inline_process_arguments {
41 my ($inv, $slot_access) = @_;
44 'my $offset = shift;',
45 'my $length = @_ ? shift : length ' . $slot_access . ';',
46 'my $replacement = shift;',
50 sub _inline_check_arguments {
52 my ($for_writer) = @_;
55 'if ($offset !~ /^-?\d+$/) {',
56 $self->_inline_throw_error(
57 '"The first argument passed to substr must be an integer"'
60 'if ($length !~ /^-?\d+$/) {',
61 $self->_inline_throw_error(
62 '"The second argument passed to substr must be an integer"'
69 'if (!Moose::Util::_STRINGLIKE0($replacement)) {',
70 $self->_inline_throw_error(
71 '"The third argument passed to substr must be a string"'
80 sub _potential_value {
82 my ($slot_access) = @_;
85 . 'my $potential = ' . $slot_access . '; '
86 . '@return = substr $potential, $offset, $length, $replacement; '
91 sub _inline_optimized_set_new_value {
93 my ($inv, $new, $slot_access) = @_;
95 return '@return = substr ' . $slot_access . ', '
96 . '$offset, $length, $replacement;';
101 my ($slot_access, $for_writer) = @_;
103 return '$return[0]' if $for_writer;
105 return 'substr ' . $slot_access . ', $offset, $length';