X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FAutobox%2FHash.pm;h=ed2305216e554174846a6ad73d7f6122d99fdce3;hb=c0ab09e353689f340e840f44b4158fc5a33790db;hp=62b894670ba2f1eb129390a7ebf5eb60d67429b1;hpb=bf86a67cef80d4a0a8a81d7b3eea213ec8a90092;p=gitmo%2FMoose-Autobox.git diff --git a/lib/Moose/Autobox/Hash.pm b/lib/Moose/Autobox/Hash.pm index 62b8946..ed23052 100644 --- a/lib/Moose/Autobox/Hash.pm +++ b/lib/Moose/Autobox/Hash.pm @@ -1,7 +1,7 @@ package Moose::Autobox::Hash; use Moose::Role 'with'; -our $VERSION = '0.03'; +our $VERSION = '0.10'; with 'Moose::Autobox::Ref', 'Moose::Autobox::Indexed'; @@ -23,6 +23,10 @@ sub hslice { return { map { $_ => $hash->{$_} } @$keys }; } +sub flatten { + return %{$_[0]} +} + # ::Indexed implementation sub at { @@ -58,7 +62,27 @@ sub kv { sub slice { my ($hash, $keys) = @_; return [ @{$hash}{@$keys} ]; -}; +} + +sub each { + my ($hash, $sub) = @_; + for my $key (CORE::keys %$hash) { + $sub->($key, $hash->{$key}); + } +} + +sub each_key { + my ($hash, $sub) = @_; + $sub->($_) for CORE::keys %$hash; +} + +sub each_value { + my ($hash, $sub) = @_; + $sub->($_) for CORE::values %$hash; +} + + +# End Indexed sub print { CORE::print %{$_[0]} } sub say { CORE::print %{$_[0]}, "\n" } @@ -98,6 +122,8 @@ shallow merging. Slices a hash but returns the keys and values as a new hashref. +=item B + =back =head2 Indexed implementation @@ -118,6 +144,12 @@ Slices a hash but returns the keys and values as a new hashref. =item B +=item B + +=item B + +=item B + =back =over 4