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=2f58a33eaa1d1e986ccb403b31a8288f7304f7e6;hpb=f7ea23f6550a15ee9ef222ff2b851eb78f803eac;p=gitmo%2FMoose-Autobox.git diff --git a/lib/Moose/Autobox/Hash.pm b/lib/Moose/Autobox/Hash.pm index 2f58a33..ed23052 100644 --- a/lib/Moose/Autobox/Hash.pm +++ b/lib/Moose/Autobox/Hash.pm @@ -1,9 +1,7 @@ package Moose::Autobox::Hash; use Moose::Role 'with'; -use Carp qw(croak); - -our $VERSION = '0.03'; +our $VERSION = '0.10'; with 'Moose::Autobox::Ref', 'Moose::Autobox::Indexed'; @@ -15,7 +13,7 @@ sub delete { sub merge { my ($left, $right) = @_; - croak "You must pass a hashref as argument to merge" + Carp::confess "You must pass a hashref as argument to merge" unless ref $right eq 'HASH'; return { %$left, %$right }; } @@ -25,6 +23,10 @@ sub hslice { return { map { $_ => $hash->{$_} } @$keys }; } +sub flatten { + return %{$_[0]} +} + # ::Indexed implementation sub at { @@ -60,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" } @@ -100,6 +122,8 @@ shallow merging. Slices a hash but returns the keys and values as a new hashref. +=item B + =back =head2 Indexed implementation @@ -120,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