Module-Starter

 view release on metacpan or  search on metacpan

lib/Module/Starter/Plugin/Template.pm  view on Meta::CPAN

package Module::Starter::Plugin::Template;

use warnings;
use strict;
use Carp qw( confess );

=head1 NAME

Module::Starter::Plugin::Template - module starter with templates

=head1 VERSION

version 1.77

=cut

our $VERSION = '1.77';

=head1 SYNOPSIS

 use Module::Starter qw(
   Module::Starter::Simple
   Module::Starter::Plugin::Template
 );

 Module::Starter->create_distro(%args);

=head1 DESCRIPTION

This plugin is designed to be added to a Module::Starter::Simple-compatible
Module::Starter class.  It adds stub methods for template retrieval and
rendering, and it replaces all of Simple's _guts methods with methods that will
retrieve and render the appropriate templates.

=head1 CLASS METHODS

=head2 C<< new(%args) >>

This plugin calls the C<new> supermethod and then initializes the template
store and renderer.  (See C<templates> and C<renderer> below.)

=cut

sub new {
    my $class = shift;
    my $self  = $class->SUPER::new(@_);
    $self->{templates} = { $self->templates };
    $self->{renderer} = $self->renderer;
    return bless $self => $class;
}

=head1 OBJECT METHODS

=head2 C<< templates() >>

This method is used to initialize the template store on the Module::Starter
object.  It returns a hash of templates; each key is a filename and each value
is the body of the template.  The filename F<Module.pm> is used for the module
template.

=cut

sub templates {
    confess 'attempted to use abstract base templates method';
}

=head2 C<< renderer() >>

This method is used to initialize the template renderer.  Its result is stored
in the object's C<renderer> entry.  The implementation will determine its use.

=cut

sub renderer {
    confess 'attempted to use abstract base renderer method';
}

=head2 C<< render($template, \%options) >>

The C<render> method will render the template passed to it, using the
data in the Module::Starter object and in the hash of passed parameters.

=cut

sub render {
    my $self = shift;
    my $template = shift;
    my $options = shift;

    confess 'attempted to use abstract base render method';
}

=head2 _guts methods

All of the C<FILE_guts> methods from Module::Starter::Simple are subclassed to
look something like this:

    sub file_guts {
        my $self = shift;
        my %options;
        @options{qw(first second third)} = @_;

        my $template = $self->{templates}{filename};
        $self->render($template, \%options);
    }

These methods will need to be rewritten when (as is likely)
Module::Starter::Simple's _guts methods are refactored into a registry.

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.657 second using v1.00-cache-2.02-grep-82fe00e-cpan-1925d2aa809 )