Additional native Hash accessors
Chris Weyl [Sat, 16 Apr 2011 02:02:42 +0000 (19:02 -0700)]
grep_keys, grep_values
map_keys, map_values
sort_keys, sort_values

lib/Moose/Meta/Method/Accessor/Native/Hash/grep_keys.pm [new file with mode: 0755]
lib/Moose/Meta/Method/Accessor/Native/Hash/grep_values.pm [new file with mode: 0755]
lib/Moose/Meta/Method/Accessor/Native/Hash/map_keys.pm [new file with mode: 0644]
lib/Moose/Meta/Method/Accessor/Native/Hash/map_values.pm [new file with mode: 0644]
lib/Moose/Meta/Method/Accessor/Native/Hash/sort_keys.pm [new file with mode: 0644]
lib/Moose/Meta/Method/Accessor/Native/Hash/sort_values.pm [new file with mode: 0644]

diff --git a/lib/Moose/Meta/Method/Accessor/Native/Hash/grep_keys.pm b/lib/Moose/Meta/Method/Accessor/Native/Hash/grep_keys.pm
new file mode 100755 (executable)
index 0000000..9221185
--- /dev/null
@@ -0,0 +1,21 @@
+package Moose::Meta::Method::Accessor::Native::Hash::grep_keys;
+
+use Moose::Role 1.15;
+
+with
+    'Moose::Meta::Method::Accessor::Native::Array::grep' => {
+        -excludes => [qw{ _return_value }],
+        -alias    => { _return_value => '_array_return_value' },
+    },
+    'Moose::Meta::Method::Accessor::Native::Hash',
+    ;
+
+sub _return_value {
+    my ($self, $slot_access) = @_;
+
+    return $self->_array_return_value("[ keys %{ $slot_access } ]");
+}
+
+no Moose::Role;
+
+1;
diff --git a/lib/Moose/Meta/Method/Accessor/Native/Hash/grep_values.pm b/lib/Moose/Meta/Method/Accessor/Native/Hash/grep_values.pm
new file mode 100755 (executable)
index 0000000..1af0df5
--- /dev/null
@@ -0,0 +1,25 @@
+package Moose::Meta::Method::Accessor::Native::Hash::grep_values;
+
+# return the sorted list of keys to the hash, a la:
+#
+#  grep { ... } values %$hash
+
+use Moose::Role 1.15;
+
+with
+    'Moose::Meta::Method::Accessor::Native::Array::grep' => {
+        -excludes => [qw{ _return_value }],
+        -alias    => { _return_value => '_array_return_value' },
+    },
+    'Moose::Meta::Method::Accessor::Native::Hash',
+    ;
+
+sub _return_value {
+    my ($self, $slot_access) = @_;
+
+    return $self->_array_return_value("[ values %{ $slot_access } ]");
+}
+
+no Moose::Role;
+
+1;
diff --git a/lib/Moose/Meta/Method/Accessor/Native/Hash/map_keys.pm b/lib/Moose/Meta/Method/Accessor/Native/Hash/map_keys.pm
new file mode 100644 (file)
index 0000000..0e30c32
--- /dev/null
@@ -0,0 +1,25 @@
+package Moose::Meta::Method::Accessor::Native::Hash::map_keys;
+
+# return the sorted list of keys to the hash, a la:
+#
+#   map { ... } keys %$hash
+
+use Moose::Role 1.15;
+
+with
+    'Moose::Meta::Method::Accessor::Native::Array::map' => {
+        -excludes => [qw{ _return_value }],
+        -alias    => { _return_value => '_array_return_value' },
+    },
+    'Moose::Meta::Method::Accessor::Native::Hash',
+    ;
+
+sub _return_value {
+    my ($self, $slot_access) = @_;
+
+    return $self->_array_return_value("[ keys %{ $slot_access } ]");
+}
+
+no Moose::Role;
+
+1;
diff --git a/lib/Moose/Meta/Method/Accessor/Native/Hash/map_values.pm b/lib/Moose/Meta/Method/Accessor/Native/Hash/map_values.pm
new file mode 100644 (file)
index 0000000..3af0736
--- /dev/null
@@ -0,0 +1,24 @@
+package Moose::Meta::Method::Accessor::Native::Hash::map_values;
+
+# return the sorted list of keys to the hash, a la:
+#
+#   map { ... } values %$hash
+
+use Moose::Role 1.15;
+
+with
+    'Moose::Meta::Method::Accessor::Native::Array::map' => {
+        -excludes => [qw{ _return_value }],
+        -alias    => { _return_value => '_array_return_value' },
+    },
+    'Moose::Meta::Method::Accessor::Native::Hash',
+    ;
+
+sub _return_value {
+    my ($self, $slot_access) = @_;
+
+    return $self->_array_return_value("[ values %{ $slot_access } ]");
+}
+
+no Moose::Role;
+1;
diff --git a/lib/Moose/Meta/Method/Accessor/Native/Hash/sort_keys.pm b/lib/Moose/Meta/Method/Accessor/Native/Hash/sort_keys.pm
new file mode 100644 (file)
index 0000000..bfc9314
--- /dev/null
@@ -0,0 +1,24 @@
+package Moose::Meta::Method::Accessor::Native::Hash::sort_keys;
+
+# return the sorted list of keys to the hash, a la:
+#
+#   sort keys %$hash
+
+use Moose::Role 1.15;
+
+with
+    'Moose::Meta::Method::Accessor::Native::Array::sort' => {
+        -excludes => [qw{ _return_value }],
+        -alias    => { _return_value => '_array_return_value' },
+    },
+    'Moose::Meta::Method::Accessor::Native::Hash',
+    ;
+
+sub _return_value {
+    my ($self, $slot_access) = @_;
+
+    return $self->_array_return_value("[ keys %{ $slot_access } ]");
+}
+
+no Moose::Role;
+1;
diff --git a/lib/Moose/Meta/Method/Accessor/Native/Hash/sort_values.pm b/lib/Moose/Meta/Method/Accessor/Native/Hash/sort_values.pm
new file mode 100644 (file)
index 0000000..358e020
--- /dev/null
@@ -0,0 +1,25 @@
+package Moose::Meta::Method::Accessor::Native::Hash::sort_values;
+
+# return the sorted list of values to the hash, a la:
+#
+#   sort values %$hash
+
+use Moose::Role 1.15;
+
+with
+    'Moose::Meta::Method::Accessor::Native::Array::sort' => {
+        -excludes => [qw{ _return_value }],
+        -alias    => { _return_value => '_array_return_value' },
+    },
+    'Moose::Meta::Method::Accessor::Native::Hash',
+    ;
+
+sub _return_value {
+    my ($self, $slot_access) = @_;
+
+    return $self->_array_return_value("[ values %{ $slot_access } ]");
+}
+
+no Moose::Role;
+
+1;