Skip to content

Instantly share code, notes, and snippets.

@nperez
Created November 20, 2009 04:27
Show Gist options
  • Save nperez/239286 to your computer and use it in GitHub Desktop.
Save nperez/239286 to your computer and use it in GitHub Desktop.
use 5.010;
use MooseX::Declare;
role Template::Declare::AutoForm::Entity(CodeRef :$tag)
{
method preamble(ClassName $name: Ref $arg?) { }
method attributes(ClassName $name: Ref $arg?) { }
method guts(ClassName $name: Ref $arg?) { }
method epilogue(ClassName $name: Ref $arg?) { }
method build(ClassName $name: Ref $arg?)
{
$name->preamble($arg);
$tag->
(
sub
{
$name->attributes($arg);
$name->guts($arg);
}
);
$name->epilogue($arg);
}
}
class UseTD
{
use MooseX::NonMoose;
use Template::Declare::Tags('HTML');
extends 'Template::Declare';
with 'Template::Declare::AutoForm::Entity' => { tag => \&div };
around guts (ClassName $class: Ref $arg?)
{
p { "Woohoo" }
}
around attributes(ClassName $class: Ref $arg?)
{
attr { 'class' => 'some_cool_class' }
}
around preamble(ClassName $class: Ref $arg?)
{
script { "var x = $$arg;" }
}
template build => \&build;
}
Template::Declare->init( dispatch_to => ['UseTD'] );
say Template::Declare->show( 'build', \2 );
__END__
produces:
<script>var x = 2;</script>
<div class="some_cool_class">
<p>Woohoo</p>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment