X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FAutobox%2FHash.pm;h=ba2eb218f42b4f5345872baa13780bd271973ce1;hb=1401ddb26bc2626f08d71808a66642f174a5c68b;hp=52238c72e529461f625f802b10b4f7bbd0743d6a;hpb=e6bb88b0e1fff9794352dde571e623ae0f4e3a95;p=gitmo%2FMoose-Autobox.git diff --git a/lib/Moose/Autobox/Hash.pm b/lib/Moose/Autobox/Hash.pm index 52238c7..ba2eb21 100644 --- a/lib/Moose/Autobox/Hash.pm +++ b/lib/Moose/Autobox/Hash.pm @@ -1,9 +1,36 @@ package Moose::Autobox::Hash; use Moose::Role 'with'; -our $VERSION = '0.01'; +use Carp qw(croak); -with 'Moose::Autobox::Ref'; +our $VERSION = '0.02'; + +with 'Moose::Autobox::Ref', + 'Moose::Autobox::Indexed'; + +sub delete { + my ($hash, $key) = @_; + CORE::delete $hash->{$key}; +} + +sub merge { + my ($left, $right) = @_; + croak "You must pass a hashref as argument to merge" + unless ref $right eq 'HASH'; + return { %$left, %$right }; +} + +# ::Indexed implementation + +sub at { + my ($hash, $index) = @_; + $hash->{$index}; +} + +sub put { + my ($hash, $index, $value) = @_; + $hash->{$index} = $value; +} sub exists { my ($hash, $key) = @_; @@ -25,4 +52,88 @@ sub kv { [ CORE::map { [ $_, $hash->{$_} ] } CORE::keys %$hash ]; } -1; \ No newline at end of file +sub print { CORE::print %{$_[0]} } +sub say { CORE::print %{$_[0]}, "\n" } + +1; + +__END__ + +=pod + +=head1 NAME + +Moose::Autobox::Hash - the Hash role + +=head1 SYNOPOSIS + + use Moose::Autobox; + + print { one => 1, two => 2 }->keys->join(', '); # prints 'one, two' + +=head1 DESCRIPTION + +This is a role to describes a Hash value. + +=head1 METHODS + +=over 4 + +=item B + +=item B + +Takes a hashref and returns a new hashref with right precedence +shallow merging. + +=back + +=head2 Indexed implementation + +=over 4 + +=item B + +=item B + +=item B + +=item B + +=item B + +=item B + +=back + +=over 4 + +=item B + +=item B + +=item B + +=back + +=head1 BUGS + +All complex software has bugs lurking in it, and this module is no +exception. If you find a bug please either email me, or add the bug +to cpan-RT. + +=head1 AUTHOR + +Stevan Little Estevan@iinteractive.comE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2006-2007 by Infinity Interactive, Inc. + +L + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut +