| Forest documentation | Contained in the Forest distribution. |
Forest::Tree::Roles::LoadWithMetaData - A Moosey solution to this problem
use Forest::Tree::Roles::LoadWithMetaData;
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.
Stevan Little <stevan.little@iinteractive.com>
Copyright 2008-2010 Infinity Interactive, Inc.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Forest documentation | Contained in the Forest distribution. |
package Forest::Tree::Roles::LoadWithMetaData; use Moose::Role; our $VERSION = '0.09'; our $AUTHORITY = 'cpan:STEVAN'; has 'metadata' => ( is => 'rw', isa => 'HashRef', default => sub { {} }, ); has 'metadata_key' => ( is => 'rw', isa => 'Str', default => sub { 'uid' }, ); around 'create_new_subtree' => sub { my $next = shift; my $self = shift; my $tree = $self->$next(@_); ($tree->does('Forest::Tree::Roles::MetaData')) || confess "Your subtrees must do the MetaData role"; my $key = $self->metadata_key; if (my $metadata = $self->metadata->{ $tree->$key() }) { $tree->metadata($metadata); } return $tree; }; no Moose::Role; 1; __END__