Forest::Tree::Roles::HasNodeFormatter - Simple role for custom node formatters


Forest documentation Contained in the Forest distribution.

Index


Code Index:

NAME

Top

Forest::Tree::Roles::HasNodeFormatter - Simple role for custom node formatters

DESCRIPTION

Top

Simple role for nodes that have custom formatters

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::HasNodeFormatter;
use Moose::Role;

our $VERSION   = '0.09';
our $AUTHORITY = 'cpan:STEVAN';

has 'node_formatter' => (
    is      => 'rw',
    isa     => 'CodeRef|Str',
    lazy    => 1,
    default => sub {
        sub { (shift)->node  || 'undef' }
    }
);

sub format_node {
    my ( $self, $node, @args ) = @_;

    my $fmt = $self->node_formatter;

    $node->$fmt(@args);
}

no Moose::Role; 1;

__END__