1 package Moose::Meta::Method::Accessor::Native::String::substr;
8 our $AUTHORITY = 'cpan:STEVAN';
12 with 'Moose::Meta::Method::Accessor::Native::Reader' => {
17 _inline_process_arguments
18 _inline_check_arguments
23 'Moose::Meta::Method::Accessor::Native::Writer' => {
29 _inline_process_arguments
30 _inline_check_arguments
31 _inline_optimized_set_new_value
37 sub _generate_method {
41 my $slot_access = $self->_get_value($inv);
45 'my ' . $inv . ' = shift;',
46 $self->_inline_curried_arguments,
47 'if (@_ == 1 || @_ == 2) {',
48 $self->_inline_reader_core($inv, $slot_access),
51 $self->_inline_writer_core($inv, $slot_access),
54 $self->_inline_check_argument_count,
60 sub _minimum_arguments { 1 }
61 sub _maximum_arguments { 3 }
63 sub _inline_process_arguments {
65 my ($inv, $slot_access) = @_;
68 'my $offset = shift;',
69 'my $length = @_ ? shift : length ' . $slot_access . ';',
70 'my $replacement = shift;',
74 sub _inline_check_arguments {
76 my ($for_writer) = @_;
79 'if ($offset !~ /^-?\d+$/) {',
80 $self->_inline_throw_error(
81 '"The first argument passed to substr must be an integer"'
84 'if ($length !~ /^-?\d+$/) {',
85 $self->_inline_throw_error(
86 '"The second argument passed to substr must be an integer"'
93 'if (!Moose::Util::_STRINGLIKE0($replacement)) {',
94 $self->_inline_throw_error(
95 '"The third argument passed to substr must be a string"'
104 sub _potential_value {
106 my ($slot_access) = @_;
109 . 'my $potential = ' . $slot_access . '; '
110 . '@return = substr $potential, $offset, $length, $replacement; '
115 sub _inline_optimized_set_new_value {
117 my ($inv, $new, $slot_access) = @_;
119 return '@return = substr ' . $slot_access . ', '
120 . '$offset, $length, $replacement;';
125 my ($slot_access, $for_writer) = @_;
127 return '$return[0]' if $for_writer;
129 return 'substr ' . $slot_access . ', $offset, $length';