Forest::Tree::Roles::LoadWithMetaData - A Moosey solution to this problem


Forest documentation Contained in the Forest distribution.

Index


Code Index:

NAME

Top

Forest::Tree::Roles::LoadWithMetaData - A Moosey solution to this problem

SYNOPSIS

Top

  use Forest::Tree::Roles::LoadWithMetaData;

DESCRIPTION

Top

METHODS

Top

BUGS

Top

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.

AUTHOR

Top

Stevan Little <stevan.little@iinteractive.com>

COPYRIGHT AND LICENSE

Top


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__