package Moose::Autobox::Hash;
use Moose::Role 'with';
-use Carp qw(croak);
-
our $VERSION = '0.03';
with 'Moose::Autobox::Ref',
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 {
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.
+
+=item B<flatten>
+
=back
=head2 Indexed implementation