MooseX::Role::TTSelf

[email protected] ("Ian Sillitoe")
Newsgroups perl.moose
Message-ID <[email protected]>
Hello,

I was developing some code to help me generate different views for a given
class and after a few iterations of refactoring I ended up with a Moose Role
that allows a class to render itself based on an associated Template file. I
did a quick search and couldn't see anything obvious that already did this -
anyone have any comments/suggestions?

Cheers,

Ian


MODULE

MooseX::Role::TTSelf

SYNOPSIS

Farm/Cow.pm

    package Farm::Cow;
    use Moose;
    with 'MooseX::Role::TTSelf';

    has 'spots' => ( is => 'rw' );

    sub moo { "Mooooooo" }

Farm/Cow.t

    This cow has [% self.spots %] spots and goes [% self.moo %]!

Elsewhere on the Farm...

    my $cow = Farm::Cow->new( spots => '8' );

    $class->render(); # "This cow has 8 spots and goes Mooooooo!"



-- 
Dr Ian Sillitoe
CATH Team -- http://cathdb.info

"Advice is what we ask for when we already know
the answer but wish we didn't" -- Erica Jong
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.