Created
August 29, 2011 19:54
-
-
Save hdp/1179234 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Stuffer; | |
use Moose; | |
has all_stuff => ( | |
isa => 'HashRef', | |
traits => ['Hash'], | |
handles => { | |
get_stuffed => 'elements', | |
_has_stuff => 'exists', | |
_get_stuff => 'get', | |
_set_stuff => 'set', | |
}, | |
); | |
sub add_stuff { | |
my ($self, %new_stuff) = @_; | |
for my $key (keys %new_stuff) { | |
$self->_set_stuff( | |
$key, | |
$self->_has_stuff($key) | |
? ($self->_get_stuff($key) . $new_stuff{$key}) | |
: $new_stuff{$key} | |
); | |
} | |
} | |
use Data::Dumper; | |
my $s = Stuffer->new; | |
$s->add_stuff(x => 1); | |
$s->add_stuff(y => 2); | |
$s->add_stuff(x => 3); | |
print Dumper { $s->get_stuffed }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment