summaryrefslogtreecommitdiff
path: root/lib/Moose/Meta/Method/Accessor/Native/String
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2015-06-06 17:50:16 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2015-06-06 17:50:16 +0000
commit5ac2026f7eed78958d69d051e7a8e993dcf51205 (patch)
tree298c3d2f08bdfe5689998b11892d72a897985be1 /lib/Moose/Meta/Method/Accessor/Native/String
downloadMoose-tarball-master.tar.gz
Diffstat (limited to 'lib/Moose/Meta/Method/Accessor/Native/String')
-rw-r--r--lib/Moose/Meta/Method/Accessor/Native/String/append.pm31
-rw-r--r--lib/Moose/Meta/Method/Accessor/Native/String/chomp.pm40
-rw-r--r--lib/Moose/Meta/Method/Accessor/Native/String/chop.pm40
-rw-r--r--lib/Moose/Meta/Method/Accessor/Native/String/clear.pm24
-rw-r--r--lib/Moose/Meta/Method/Accessor/Native/String/inc.pm33
-rw-r--r--lib/Moose/Meta/Method/Accessor/Native/String/length.pm22
-rw-r--r--lib/Moose/Meta/Method/Accessor/Native/String/match.pm42
-rw-r--r--lib/Moose/Meta/Method/Accessor/Native/String/prepend.pm31
-rw-r--r--lib/Moose/Meta/Method/Accessor/Native/String/replace.pm69
-rw-r--r--lib/Moose/Meta/Method/Accessor/Native/String/substr.pm123
10 files changed, 455 insertions, 0 deletions
diff --git a/lib/Moose/Meta/Method/Accessor/Native/String/append.pm b/lib/Moose/Meta/Method/Accessor/Native/String/append.pm
new file mode 100644
index 0000000..e941e5a
--- /dev/null
+++ b/lib/Moose/Meta/Method/Accessor/Native/String/append.pm
@@ -0,0 +1,31 @@
+package Moose::Meta::Method::Accessor::Native::String::append;
+our $VERSION = '2.1405';
+
+use strict;
+use warnings;
+
+use Moose::Role;
+
+with 'Moose::Meta::Method::Accessor::Native::Writer';
+
+sub _minimum_arguments { 1 }
+
+sub _maximum_arguments { 1 }
+
+sub _potential_value {
+ my $self = shift;
+ my ($slot_access) = @_;
+
+ return '( ' . $slot_access . ' . $_[0] )';
+}
+
+sub _inline_optimized_set_new_value {
+ my $self = shift;
+ my ($inv, $new, $slot_access) = @_;
+
+ return $slot_access . ' .= $_[0];';
+}
+
+no Moose::Role;
+
+1;
diff --git a/lib/Moose/Meta/Method/Accessor/Native/String/chomp.pm b/lib/Moose/Meta/Method/Accessor/Native/String/chomp.pm
new file mode 100644
index 0000000..49e2215
--- /dev/null
+++ b/lib/Moose/Meta/Method/Accessor/Native/String/chomp.pm
@@ -0,0 +1,40 @@
+package Moose::Meta::Method::Accessor::Native::String::chomp;
+our $VERSION = '2.1405';
+
+use strict;
+use warnings;
+
+use Moose::Role;
+
+with 'Moose::Meta::Method::Accessor::Native::Writer';
+
+sub _maximum_arguments { 0 }
+
+sub _potential_value {
+ my $self = shift;
+ my ($slot_access) = @_;
+
+ return '(do { '
+ . 'my $val = ' . $slot_access . '; '
+ . '@return = chomp $val; '
+ . '$val '
+ . '})';
+}
+
+sub _inline_optimized_set_new_value {
+ my $self = shift;
+ my ($inv, $new, $slot_access) = @_;
+
+ return '@return = chomp ' . $slot_access . ';';
+}
+
+sub _return_value {
+ my $self = shift;
+ my ($slot_access) = @_;
+
+ return '$return[0]';
+}
+
+no Moose::Role;
+
+1;
diff --git a/lib/Moose/Meta/Method/Accessor/Native/String/chop.pm b/lib/Moose/Meta/Method/Accessor/Native/String/chop.pm
new file mode 100644
index 0000000..c15fd0f
--- /dev/null
+++ b/lib/Moose/Meta/Method/Accessor/Native/String/chop.pm
@@ -0,0 +1,40 @@
+package Moose::Meta::Method::Accessor::Native::String::chop;
+our $VERSION = '2.1405';
+
+use strict;
+use warnings;
+
+use Moose::Role;
+
+with 'Moose::Meta::Method::Accessor::Native::Writer';
+
+sub _maximum_arguments { 0 }
+
+sub _potential_value {
+ my $self = shift;
+ my ($slot_access) = @_;
+
+ return '(do { '
+ . 'my $val = ' . $slot_access . '; '
+ . '@return = chop $val; '
+ . '$val; '
+ . '})';
+}
+
+sub _inline_optimized_set_new_value {
+ my $self = shift;
+ my ($inv, $new, $slot_access) = @_;
+
+ return '@return = chop ' . $slot_access . ';';
+}
+
+sub _return_value {
+ my $self = shift;
+ my ($slot_access) = @_;
+
+ return '$return[0]';
+}
+
+no Moose::Role;
+
+1;
diff --git a/lib/Moose/Meta/Method/Accessor/Native/String/clear.pm b/lib/Moose/Meta/Method/Accessor/Native/String/clear.pm
new file mode 100644
index 0000000..7aec2c5
--- /dev/null
+++ b/lib/Moose/Meta/Method/Accessor/Native/String/clear.pm
@@ -0,0 +1,24 @@
+package Moose::Meta::Method::Accessor::Native::String::clear;
+our $VERSION = '2.1405';
+
+use strict;
+use warnings;
+
+use Moose::Role;
+
+with 'Moose::Meta::Method::Accessor::Native::Writer';
+
+sub _maximum_arguments { 0 }
+
+sub _potential_value { '""' }
+
+sub _inline_optimized_set_new_value {
+ my $self = shift;
+ my ($inv, $new, $slot_access) = @_;
+
+ return $slot_access . ' = "";';
+}
+
+no Moose::Role;
+
+1;
diff --git a/lib/Moose/Meta/Method/Accessor/Native/String/inc.pm b/lib/Moose/Meta/Method/Accessor/Native/String/inc.pm
new file mode 100644
index 0000000..3ee5605
--- /dev/null
+++ b/lib/Moose/Meta/Method/Accessor/Native/String/inc.pm
@@ -0,0 +1,33 @@
+package Moose::Meta::Method::Accessor::Native::String::inc;
+our $VERSION = '2.1405';
+
+use strict;
+use warnings;
+
+use Moose::Role;
+
+with 'Moose::Meta::Method::Accessor::Native::Writer';
+
+sub _maximum_arguments { 0 }
+
+sub _potential_value {
+ my $self = shift;
+ my ($slot_access) = @_;
+
+ return '(do { '
+ . 'my $val = ' . $slot_access . '; '
+ . '$val++; '
+ . '$val; '
+ . '})';
+}
+
+sub _inline_optimized_set_new_value {
+ my $self = shift;
+ my ($inv, $new, $slot_access) = @_;
+
+ return $slot_access . '++;';
+}
+
+no Moose::Role;
+
+1;
diff --git a/lib/Moose/Meta/Method/Accessor/Native/String/length.pm b/lib/Moose/Meta/Method/Accessor/Native/String/length.pm
new file mode 100644
index 0000000..bf40b40
--- /dev/null
+++ b/lib/Moose/Meta/Method/Accessor/Native/String/length.pm
@@ -0,0 +1,22 @@
+package Moose::Meta::Method::Accessor::Native::String::length;
+our $VERSION = '2.1405';
+
+use strict;
+use warnings;
+
+use Moose::Role;
+
+with 'Moose::Meta::Method::Accessor::Native::Reader';
+
+sub _maximum_arguments { 0 }
+
+sub _return_value {
+ my $self = shift;
+ my ($slot_access) = @_;
+
+ return 'length ' . $slot_access;
+}
+
+no Moose::Role;
+
+1;
diff --git a/lib/Moose/Meta/Method/Accessor/Native/String/match.pm b/lib/Moose/Meta/Method/Accessor/Native/String/match.pm
new file mode 100644
index 0000000..ae85a96
--- /dev/null
+++ b/lib/Moose/Meta/Method/Accessor/Native/String/match.pm
@@ -0,0 +1,42 @@
+package Moose::Meta::Method::Accessor::Native::String::match;
+our $VERSION = '2.1405';
+
+use strict;
+use warnings;
+
+use Moose::Util ();
+use Params::Util ();
+
+use Moose::Role;
+
+with 'Moose::Meta::Method::Accessor::Native::Reader';
+
+sub _minimum_arguments { 1 }
+
+sub _maximum_arguments { 1 }
+
+sub _inline_check_arguments {
+ my $self = shift;
+
+ return (
+ 'if (!Moose::Util::_STRINGLIKE0($_[0]) && !Params::Util::_REGEX($_[0])) {',
+ $self->_inline_throw_exception( InvalidArgumentToMethod =>
+ 'argument => $_[0],'.
+ 'type => "Str|RegexpRef",'.
+ 'type_of_argument => "string or regexp reference",'.
+ 'method_name => "match"',
+ ) . ';',
+ '}',
+ );
+}
+
+sub _return_value {
+ my $self = shift;
+ my ($slot_access) = @_;
+
+ return $slot_access . ' =~ $_[0]';
+}
+
+no Moose::Role;
+
+1;
diff --git a/lib/Moose/Meta/Method/Accessor/Native/String/prepend.pm b/lib/Moose/Meta/Method/Accessor/Native/String/prepend.pm
new file mode 100644
index 0000000..87a0695
--- /dev/null
+++ b/lib/Moose/Meta/Method/Accessor/Native/String/prepend.pm
@@ -0,0 +1,31 @@
+package Moose::Meta::Method::Accessor::Native::String::prepend;
+our $VERSION = '2.1405';
+
+use strict;
+use warnings;
+
+use Moose::Role;
+
+with 'Moose::Meta::Method::Accessor::Native::Writer';
+
+sub _minimum_arguments { 1 }
+
+sub _maximum_arguments { 1 }
+
+sub _potential_value {
+ my $self = shift;
+ my ($slot_access) = @_;
+
+ return '$_[0] . ' . $slot_access;
+}
+
+sub _inline_optimized_set_new_value {
+ my $self = shift;
+ my ($inv, $new, $slot_access) = @_;
+
+ return $slot_access . ' = $_[0] . ' . $slot_access . ';';
+}
+
+no Moose::Role;
+
+1;
diff --git a/lib/Moose/Meta/Method/Accessor/Native/String/replace.pm b/lib/Moose/Meta/Method/Accessor/Native/String/replace.pm
new file mode 100644
index 0000000..6e33609
--- /dev/null
+++ b/lib/Moose/Meta/Method/Accessor/Native/String/replace.pm
@@ -0,0 +1,69 @@
+package Moose::Meta::Method::Accessor::Native::String::replace;
+our $VERSION = '2.1405';
+
+use strict;
+use warnings;
+
+use Moose::Util ();
+use Params::Util ();
+
+use Moose::Role;
+
+with 'Moose::Meta::Method::Accessor::Native::Writer';
+
+sub _minimum_arguments { 1 }
+
+sub _maximum_arguments { 2 }
+
+sub _inline_check_arguments {
+ my $self = shift;
+
+ return (
+ 'if (!Moose::Util::_STRINGLIKE0($_[0]) && !Params::Util::_REGEX($_[0])) {',
+ $self->_inline_throw_exception( InvalidArgumentToMethod =>
+ 'argument => $_[0],'.
+ 'method_name => "replace",'.
+ 'ordinal => "first",'.
+ 'type_of_argument => "string or regexp reference",'.
+ 'type => "Str|RegexpRef"',
+ ) . ';',
+ '}',
+ 'if (!Moose::Util::_STRINGLIKE0($_[1]) && !Params::Util::_CODELIKE($_[1])) {',
+ $self->_inline_throw_exception( InvalidArgumentToMethod =>
+ 'argument => $_[1],'.
+ 'method_name => "replace",'.
+ 'ordinal => "second",'.
+ 'type_of_argument => "string or code reference",'.
+ 'type => "Str|CodeRef"',
+ ) . ';',
+ '}',
+ );
+}
+
+sub _potential_value {
+ my $self = shift;
+ my ($slot_access) = @_;
+
+ return '(do { '
+ . 'my $val = ' . $slot_access . '; '
+ . 'ref $_[1] '
+ . '? $val =~ s/$_[0]/$_[1]->()/e '
+ . ': $val =~ s/$_[0]/$_[1]/; '
+ . '$val; '
+ . '})';
+}
+
+sub _inline_optimized_set_new_value {
+ my $self = shift;
+ my ($inv, $new, $slot_access) = @_;
+
+ return (
+ 'ref $_[1]',
+ '? ' . $slot_access . ' =~ s/$_[0]/$_[1]->()/e',
+ ': ' . $slot_access . ' =~ s/$_[0]/$_[1]/;',
+ );
+}
+
+no Moose::Role;
+
+1;
diff --git a/lib/Moose/Meta/Method/Accessor/Native/String/substr.pm b/lib/Moose/Meta/Method/Accessor/Native/String/substr.pm
new file mode 100644
index 0000000..df82e23
--- /dev/null
+++ b/lib/Moose/Meta/Method/Accessor/Native/String/substr.pm
@@ -0,0 +1,123 @@
+package Moose::Meta::Method::Accessor::Native::String::substr;
+our $VERSION = '2.1405';
+
+use strict;
+use warnings;
+
+use Moose::Util ();
+
+use Moose::Role;
+
+with 'Moose::Meta::Method::Accessor::Native::Reader',
+ 'Moose::Meta::Method::Accessor::Native::Writer';
+
+sub _generate_method {
+ my $self = shift;
+
+ my $inv = '$self';
+ my $slot_access = $self->_get_value($inv);
+
+ return (
+ 'sub {',
+ 'my ' . $inv . ' = shift;',
+ $self->_inline_curried_arguments,
+ 'if (@_ == 1 || @_ == 2) {',
+ $self->_inline_reader_core($inv, $slot_access),
+ '}',
+ 'elsif (@_ == 3) {',
+ $self->_inline_writer_core($inv, $slot_access),
+ '}',
+ 'else {',
+ $self->_inline_check_argument_count,
+ '}',
+ '}',
+ );
+}
+
+sub _minimum_arguments { 1 }
+sub _maximum_arguments { 3 }
+
+sub _inline_process_arguments {
+ my $self = shift;
+ my ($inv, $slot_access) = @_;
+
+ return (
+ 'my $offset = shift;',
+ 'my $length = @_ ? shift : length ' . $slot_access . ';',
+ 'my $replacement = shift;',
+ );
+}
+
+sub _inline_check_arguments {
+ my $self = shift;
+ my ($for_writer) = @_;
+
+ my @code = (
+ 'if ($offset !~ /^-?\d+$/) {',
+ $self->_inline_throw_exception( InvalidArgumentToMethod =>
+ 'argument => $offset,'.
+ 'ordinal => "first",'.
+ 'type_of_argument => "integer",'.
+ 'method_name => "substr",'.
+ 'type => "Int"',
+ ) . ';',
+ '}',
+ 'if ($length !~ /^-?\d+$/) {',
+ $self->_inline_throw_exception( InvalidArgumentToMethod =>
+ 'argument => $length,'.
+ 'ordinal => "second",'.
+ 'type_of_argument => "integer",'.
+ 'method_name => "substr",'.
+ 'type => "Int"',
+ ) . ';',
+ '}',
+ );
+
+ if ($for_writer) {
+ push @code, (
+ 'if (!Moose::Util::_STRINGLIKE0($replacement)) {',
+ $self->_inline_throw_exception( InvalidArgumentToMethod =>
+ 'argument => $replacement,'.
+ 'ordinal => "third",'.
+ 'type_of_argument => "string",'.
+ 'method_name => "substr",'.
+ 'type => "Str"',
+ ) . ';',
+ '}',
+ );
+ }
+
+ return @code;
+}
+
+sub _potential_value {
+ my $self = shift;
+ my ($slot_access) = @_;
+
+ return '(do { '
+ . 'my $potential = ' . $slot_access . '; '
+ . '@return = substr $potential, $offset, $length, $replacement; '
+ . '$potential; '
+ . '})';
+}
+
+sub _inline_optimized_set_new_value {
+ my $self = shift;
+ my ($inv, $new, $slot_access) = @_;
+
+ return '@return = substr ' . $slot_access . ', '
+ . '$offset, $length, $replacement;';
+}
+
+sub _return_value {
+ my $self = shift;
+ my ($slot_access, $for_writer) = @_;
+
+ return '$return[0]' if $for_writer;
+
+ return 'substr ' . $slot_access . ', $offset, $length';
+}
+
+no Moose::Role;
+
+1;