Module::New::Template - Module::New::Template documentation


Module-New documentation Contained in the Module-New distribution.

Index


Code Index:

NAME

Top

Module::New::Template

SYNOPSIS

Top

  my $text = Module::New::Template->render('<% $c->module %>');

DESCRIPTION

Top

As of 0.02, Module::New uses a Mojo::Template-like template engine. See Mojo::Template for how to write templates.

METHOD

Top

render

takes a template, and returns a rendered text. Note that $c represents the Module::New context (which is passed to the template internally).

AUTHOR

Top

Kenichi Ishigaki, <ishigaki@cpan.org>

COPYRIGHT AND LICENSE

Top


Module-New documentation Contained in the Module-New distribution.

package Module::New::Template;

use strict;
use warnings;
use Text::MicroTemplate ();

# XXX: I'm still wondering if I should use Mojo::Template here...
my $ENGINE = Text::MicroTemplate->new(
  expression_mark => '=',
  line_start      => '%',
  tag_start       => '<%',
  tag_end         => '%>',
);

sub render {
  my ($self, $template) = @_;

  $template = '% my $c = shift;'."\n".$template;
  $ENGINE->parse($template)->build->(Module::New->context)->as_string;
}

1;

__END__