X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FAutobox%2FHash.pm;h=de8f2bbe5b33e74877cdca334ae7003b61a96978;hb=2197a7c093124739caaae6be7b9ae213daefb598;hp=270f4aee64b1bd4225e70d78f7ef7e74bf93b576;hpb=bc9177cb2a3f27e0480556babfdc55ee4fa66628;p=gitmo%2FMoose-Autobox.git diff --git a/lib/Moose/Autobox/Hash.pm b/lib/Moose/Autobox/Hash.pm index 270f4ae..de8f2bb 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.02'; +our $VERSION = '0.03'; with 'Moose::Autobox::Ref', 'Moose::Autobox::Indexed'; @@ -15,11 +13,20 @@ 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 }; } +sub hslice { + my ($hash, $keys) = @_; + return { map { $_ => $hash->{$_} } @$keys }; +} + +sub flatten { + return %{$_[0]} +} + # ::Indexed implementation sub at { @@ -52,6 +59,14 @@ sub kv { [ CORE::map { [ $_, $hash->{$_} ] } CORE::keys %$hash ]; } +sub slice { + my ($hash, $keys) = @_; + return [ @{$hash}{@$keys} ]; +}; + +sub print { CORE::print %{$_[0]} } +sub say { CORE::print %{$_[0]}, "\n" } + 1; __END__ @@ -83,6 +98,12 @@ This is a role to describes a Hash value. Takes a hashref and returns a new hashref with right precedence shallow merging. +=item B + +Slices a hash but returns the keys and values as a new hashref. + +=item B + =back =head2 Indexed implementation @@ -101,12 +122,18 @@ shallow merging. =item B +=item B + =back =over 4 =item B +=item B + +=item B + =back =head1 BUGS @@ -119,11 +146,9 @@ to cpan-RT. Stevan Little Estevan@iinteractive.comE -Anders Nor Berle Edebolaz@gmail.comE - =head1 COPYRIGHT AND LICENSE -Copyright 2006 by Infinity Interactive, Inc. +Copyright 2006-2008 by Infinity Interactive, Inc. L