| 1 | package Moose::Meta::Method::Accessor::Native::String::substr; | ||||||||||
| 2 | 4 | our $VERSION = '2.4001'; | |||||||||
| 3 | |||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 4 | ▶ | use Moose::Util (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 4 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 4 | with 'Moose::Meta::Method::Accessor::Native::Reader', | |||||||||
| 12 | 'Moose::Meta::Method::Accessor::Native::Writer'; | ||||||||||
| 13 | |||||||||||
| 14 | 31 | ▶ | sub _generate_method { | ||||||||
|
Subroutine
_generate_method: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 31 | my $self = shift; | |||||||||
| 16 | |||||||||||
| 17 | 31 | my $inv = '$self'; | |||||||||
| 18 | 31 | my $slot_access = $self->_get_value($inv); | |||||||||
| 19 | |||||||||||
| 20 | return ( | ||||||||||
| 21 | 31 | 'sub {', | |||||||||
| 22 | 'my ' . $inv . ' = shift;', | ||||||||||
| 23 | $self->_inline_curried_arguments, | ||||||||||
| 24 | 'if (@_ == 1 || @_ == 2) {', | ||||||||||
| 25 | $self->_inline_reader_core($inv, $slot_access), | ||||||||||
| 26 | '}', | ||||||||||
| 27 | 'elsif (@_ == 3) {', | ||||||||||
| 28 | $self->_inline_writer_core($inv, $slot_access), | ||||||||||
| 29 | '}', | ||||||||||
| 30 | 'else {', | ||||||||||
| 31 | $self->_inline_check_argument_count, | ||||||||||
| 32 | '}', | ||||||||||
| 33 | '}', | ||||||||||
| 34 | ); | ||||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | 93 | ▶ | sub _minimum_arguments { 1 } | ||||||||
|
Subroutine
_minimum_arguments: called CC=1 SCAR=0.0
| |||||||||||
| 38 | 93 | ▶ | sub _maximum_arguments { 3 } | ||||||||
|
Subroutine
_maximum_arguments: called CC=1 SCAR=0.0
| |||||||||||
| 39 | |||||||||||
| 40 | 62 | ▶ | sub _inline_process_arguments { | ||||||||
|
Subroutine
_inline_process_arguments: called CC=1 SCAR=0.0
| |||||||||||
| 41 | 62 | my $self = shift; | |||||||||
| 42 | 62 | my ($inv, $slot_access) = @_; | |||||||||
| 43 | |||||||||||
| 44 | return ( | ||||||||||
| 45 | 62 | 'my $offset = shift;', | |||||||||
| 46 | 'my $length = @_ ? shift : length ' . $slot_access . ';', | ||||||||||
| 47 | 'my $replacement = shift;', | ||||||||||
| 48 | ); | ||||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 62 | ▶ | sub _inline_check_arguments { | ||||||||
|
Subroutine
_inline_check_arguments: called CC=2 SCAR=6.9
| |||||||||||
| 52 | 62 | my $self = shift; | |||||||||
| 53 | 62 | my ($for_writer) = @_; | |||||||||
| 54 | |||||||||||
| 55 | 62 | my @code = ( | |||||||||
| 56 | 'if ($offset !~ /^-?\d+$/) {', | ||||||||||
| 57 | $self->_inline_throw_exception( InvalidArgumentToMethod => | ||||||||||
| 58 | 'argument => $offset,'. | ||||||||||
| 59 | 'ordinal => "first",'. | ||||||||||
| 60 | 'type_of_argument => "integer",'. | ||||||||||
| 61 | 'method_name => "substr",'. | ||||||||||
| 62 | 'type => "Int"', | ||||||||||
| 63 | ) . ';', | ||||||||||
| 64 | '}', | ||||||||||
| 65 | 'if ($length !~ /^-?\d+$/) {', | ||||||||||
| 66 | $self->_inline_throw_exception( InvalidArgumentToMethod => | ||||||||||
| 67 | 'argument => $length,'. | ||||||||||
| 68 | 'ordinal => "second",'. | ||||||||||
| 69 | 'type_of_argument => "integer",'. | ||||||||||
| 70 | 'method_name => "substr",'. | ||||||||||
| 71 | 'type => "Int"', | ||||||||||
| 72 | ) . ';', | ||||||||||
| 73 | '}', | ||||||||||
| 74 | ); | ||||||||||
| 75 | |||||||||||
| 76 | 62 | ▶ | if ($for_writer) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 77 | 31 | push @code, ( | |||||||||
| 78 | 'if (!Moose::Util::_STRINGLIKE0($replacement)) {', | ||||||||||
| 79 | $self->_inline_throw_exception( InvalidArgumentToMethod => | ||||||||||
| 80 | 'argument => $replacement,'. | ||||||||||
| 81 | 'ordinal => "third",'. | ||||||||||
| 82 | 'type_of_argument => "string",'. | ||||||||||
| 83 | 'method_name => "substr",'. | ||||||||||
| 84 | 'type => "Str"', | ||||||||||
| 85 | ) . ';', | ||||||||||
| 86 | '}', | ||||||||||
| 87 | ); | ||||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | 62 | return @code; | |||||||||
| 91 | } | ||||||||||
| 92 | |||||||||||
| 93 | 31 | ▶ | sub _potential_value { | ||||||||
|
Subroutine
_potential_value: called CC=1 SCAR=0.0
| |||||||||||
| 94 | 31 | my $self = shift; | |||||||||
| 95 | 31 | my ($slot_access) = @_; | |||||||||
| 96 | |||||||||||
| 97 | 31 | return '(do { ' | |||||||||
| 98 | . 'my $potential = ' . $slot_access . '; ' | ||||||||||
| 99 | . '@return = substr $potential, $offset, $length, $replacement; ' | ||||||||||
| 100 | . '$potential; ' | ||||||||||
| 101 | . '})'; | ||||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | 15 | ▶ | sub _inline_optimized_set_new_value { | ||||||||
|
Subroutine
_inline_optimized_set_new_value: called CC=1 SCAR=0.0
| |||||||||||
| 105 | 15 | my $self = shift; | |||||||||
| 106 | 15 | my ($inv, $new, $slot_access) = @_; | |||||||||
| 107 | |||||||||||
| 108 | 15 | return '@return = substr ' . $slot_access . ', ' | |||||||||
| 109 | . '$offset, $length, $replacement;'; | ||||||||||
| 110 | } | ||||||||||
| 111 | |||||||||||
| 112 | 93 | ▶ | sub _return_value { | ||||||||
|
Subroutine
_return_value: called CC=2 SCAR=6.9
| |||||||||||
| 113 | 93 | my $self = shift; | |||||||||
| 114 | 93 | my ($slot_access, $for_writer) = @_; | |||||||||
| 115 | |||||||||||
| 116 | 93 | ▶ | return '$return[0]' if $for_writer; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 117 | |||||||||||
| 118 | 62 | return 'substr ' . $slot_access . ', $offset, $length'; | |||||||||
| 119 | } | ||||||||||
| 120 | |||||||||||
| 121 | 4 | ▶ | no Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 122 | |||||||||||
| 123 | 4 | 1; | |||||||||