My current Perl Ironman Challenge status is: My Ironman Badge

Monday, November 16, 2009

Template::Declare + MooseX::Declare == Win

So, I've been playing around with getting TD to work with MXD nicely. This is the result for the most part:
use 5.010;
use MooseX::Declare;
class Blarg
{
use MooseX::NonMoose;
use Template::Declare::Tags('HTML');
extends 'Template::Declare';
method foo(ClassName $class: Int $thing) { div { p { "My thing is: $thing" } } }
around foo(ClassName $class: Int $thing) { div { attr { class => 'wrapper'}; $class->$orig($thing); } }
template foo => \&foo
}
Template::Declare->init( dispatch_to => ['Blarg'] );
say Template::Declare->show( 'foo', 2 );
__END__
produces:
<div class="wrapper">
<div>
<p>My thing is: 2</p>
</div>
</div>
view raw scary_td+mxd.pl hosted with ❤ by GitHub


What this will buy me is a more sane wrapper strategy with role application. I'd rather have 'around' keywords than the insanity that is TD's create_wrapper stuff. But mainly, I want type constraint checking that comes with MooseX::Method::Signatures. In the end, this is win. This lets me step back a little bit from TD, write some sanity, and then hook it up to the dispatcher via the template() function.

Granted it is a little unwieldy at first, but I am thinking I could distill this out into it's own thingy. We will see as the week progresses.

2 comments:

  1. Hi, I have a couple jobs that I would like to advertise on your site or via an email list to inform your readers about Perl programming jobs. Please get back to me as soon as you get a chance.

    Look forward to hearing from you.

    Chris

    ReplyDelete