1 package Moose::Meta::Method::Accessor::Native::String::substr;
9 $VERSION = eval $VERSION;
10 our $AUTHORITY = 'cpan:STEVAN';
14 with 'Moose::Meta::Method::Accessor::Native::Reader' => {
19 _inline_process_arguments
20 _inline_check_arguments
25 'Moose::Meta::Method::Accessor::Native::Writer' => {
31 _inline_process_arguments
32 _inline_check_arguments
33 _optimized_set_new_value
39 sub _generate_method {
43 my $slot_access = $self->_inline_get($inv);
47 $self->_inline_pre_body(@_),
48 'my ' . $inv . ' = shift;',
49 $self->_inline_curried_arguments,
50 'if (@_ == 1 || @_ == 2) {',
51 $self->_reader_core($inv, $slot_access),
54 $self->_writer_core($inv, $slot_access),
55 $self->_inline_post_body(@_),
58 $self->_inline_check_argument_count,
64 sub _minimum_arguments {1}
65 sub _maximum_arguments {3}
67 sub _inline_process_arguments {
69 my ($inv, $slot_access) = @_;
72 'my $offset = shift;',
73 'my $length = @_ ? shift : length ' . $slot_access . ';',
74 'my $replacement = shift;',
78 sub _inline_check_arguments {
80 my ($for_writer) = @_;
83 'if ($offset !~ /^-?\d+$/) {',
84 $self->_inline_throw_error(
85 '"The first argument passed to substr must be an integer"'
88 'if ($length !~ /^-?\d+$/) {',
89 $self->_inline_throw_error(
90 '"The second argument passed to substr must be an integer"'
97 'if (!Moose::Util::_STRINGLIKE0($replacement)) {',
98 $self->_inline_throw_error(
99 '"The third argument passed to substr must be a string"'
108 sub _potential_value {
110 my ($slot_access) = @_;
113 . 'my $potential = ' . $slot_access . '; '
114 . '@return = substr $potential, $offset, $length, $replacement; '
119 sub _optimized_set_new_value {
121 my ($inv, $new, $slot_access) = @_;
123 return '@return = substr ' . $slot_access . ', '
124 . '$offset, $length, $replacement';
129 my ($slot_access, $for_writer) = @_;
131 return '$return[0]' if $for_writer;
133 return 'substr ' . $slot_access . ', $offset, $length';