1 package Moose::Meta::Method::Accessor::Native::String::substr;
8 our $VERSION = '1.9900';
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 _inline_optimized_set_new_value
39 sub _generate_method {
43 my $slot_access = $self->_get_value($inv);
47 'my ' . $inv . ' = shift;',
48 $self->_inline_curried_arguments,
49 'if (@_ == 1 || @_ == 2) {',
50 $self->_inline_reader_core($inv, $slot_access),
53 $self->_inline_writer_core($inv, $slot_access),
56 $self->_inline_check_argument_count,
62 sub _minimum_arguments { 1 }
63 sub _maximum_arguments { 3 }
65 sub _inline_process_arguments {
67 my ($inv, $slot_access) = @_;
70 'my $offset = shift;',
71 'my $length = @_ ? shift : length ' . $slot_access . ';',
72 'my $replacement = shift;',
76 sub _inline_check_arguments {
78 my ($for_writer) = @_;
81 'if ($offset !~ /^-?\d+$/) {',
82 $self->_inline_throw_error(
83 '"The first argument passed to substr must be an integer"'
86 'if ($length !~ /^-?\d+$/) {',
87 $self->_inline_throw_error(
88 '"The second argument passed to substr must be an integer"'
95 'if (!Moose::Util::_STRINGLIKE0($replacement)) {',
96 $self->_inline_throw_error(
97 '"The third argument passed to substr must be a string"'
106 sub _potential_value {
108 my ($slot_access) = @_;
111 . 'my $potential = ' . $slot_access . '; '
112 . '@return = substr $potential, $offset, $length, $replacement; '
117 sub _inline_optimized_set_new_value {
119 my ($inv, $new, $slot_access) = @_;
121 return '@return = substr ' . $slot_access . ', '
122 . '$offset, $length, $replacement;';
127 my ($slot_access, $for_writer) = @_;
129 return '$return[0]' if $for_writer;
131 return 'substr ' . $slot_access . ', $offset, $length';