From: Chris Weyl Date: Sat, 16 Apr 2011 02:02:42 +0000 (-0700) Subject: Additional native Hash accessors X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=818e85ad8eeb35f054f7ec747dc29ecf2a057a69;p=gitmo%2FMoose.git Additional native Hash accessors grep_keys, grep_values map_keys, map_values sort_keys, sort_values --- 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 index 0000000..9221185 --- /dev/null +++ b/lib/Moose/Meta/Method/Accessor/Native/Hash/grep_keys.pm @@ -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 index 0000000..1af0df5 --- /dev/null +++ b/lib/Moose/Meta/Method/Accessor/Native/Hash/grep_values.pm @@ -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 index 0000000..0e30c32 --- /dev/null +++ b/lib/Moose/Meta/Method/Accessor/Native/Hash/map_keys.pm @@ -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 index 0000000..3af0736 --- /dev/null +++ b/lib/Moose/Meta/Method/Accessor/Native/Hash/map_values.pm @@ -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 index 0000000..bfc9314 --- /dev/null +++ b/lib/Moose/Meta/Method/Accessor/Native/Hash/sort_keys.pm @@ -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 index 0000000..358e020 --- /dev/null +++ b/lib/Moose/Meta/Method/Accessor/Native/Hash/sort_values.pm @@ -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;