MooseX::Traits::Attribute::MergeHashRef
version 1.002
package MyClass; use Moose; has stash => ( is => 'rw', isa => 'HashRef', traits => [qw(MergeHashRef)] ); my $class = MyClass->new; $class->stash({ animals => { dogs => 1 } }); # $class->stash: { animals => { dogs => 1 } } $class->stash({ animals => { cats => 2 } }); # $class->stash: { animals => { dogs => 1, cats => 2 } } $class->set_stash({ foo => bar }); # $class->stash: { foo => bar }); $class->clear_stash; # $class->stash: undef
This trait will merge values added to a HashRef attribute. It uses Hash::Merge to combine them. The method set_$attr which resets the attribute with a given hashref is also created. Call clear_$attr to clear the attribute.
set_$attr
clear_$attr
MooseX::Traits::Attribute::MergeHashRef - Merging HashRef attribute
Moritz Onken
This software is Copyright (c) 2011 by Moritz Onken.
This is free software, licensed under:
The (three-clause) BSD License
To install MooseX::Traits::Attribute::MergeHashRef, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::Traits::Attribute::MergeHashRef
CPAN shell
perl -MCPAN -e shell install MooseX::Traits::Attribute::MergeHashRef
For more information on module installation, please visit the detailed CPAN module installation guide.