return { %$left, %$right };
}
+sub hslice {
+ my ($hash, $keys) = @_;
+ return { map { $_ => $hash->{$_} } @$keys };
+}
+
# ::Indexed implementation
sub at {
Takes a hashref and returns a new hashref with right precedence
shallow merging.
+=item B<hslice>
+
+Slices a hash but returns the keys and values as a new hashref.
+
=back
=head2 Indexed implementation
use strict;
use warnings;
-use Test::More tests => 63;
+use Test::More tests => 64;
BEGIN {
use_ok('Moose::Autobox');
is_deeply( { one => 1, two => 2, three => 3 }->slice([qw/three one/]),
[ qw/3 1/ ],
'... hash slices ok' );
+
+is_deeply( { one => 1, two => 2, three => 3 }->hslice([qw/two three/]),
+ { two => 2, three => 3 },
+ '... hash hslices ok' );