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


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

Index


Code Index:

NAME

Top

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

VERSION

Top

Version 1.57

SYNOPSIS

Top

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

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

DESCRIPTION

Top

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 apropriate templates.

CLASS METHODS

Top

new(%args)

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

OBJECT METHODS

Top

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 Module.pm is used for the module template.

renderer()

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

render($template, \%options)

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

_guts methods

All of the 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.

module_guts
Makefile_PL_guts
MI_Makefile_PL_guts
Build_PL_guts
Changes_guts
README_guts
t_guts
MANIFEST_guts
item ignores_guts

AUTHOR

Top

Ricardo SIGNES, <rjbs at cpan.org>

Bugs

Top

Please report any bugs or feature requests to bug-module-starter at rt.cpan.org, or through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

COPYRIGHT

Top


Module-Starter documentation Contained in the Module-Starter distribution.
package Module::Starter::Plugin::Template;

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

our $VERSION = '1.57';

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

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

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

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

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

sub module_guts {
    my $self = shift;
    my %options;
    @options{qw(module rtname)} = @_;

    my $template = $self->{templates}{'Module.pm'};
    $self->render($template, \%options);
}

sub Makefile_PL_guts {
    my $self = shift;
    my %options;
    @options{qw(main_module main_pm_file)} = @_;

    my $template = $self->{templates}{'Makefile.PL'};
    $self->render($template, \%options);
}

sub MI_Makefile_PL_guts {
    my $self = shift;
    my %options;
    @options{qw(main_module main_pm_file)} = @_;

    my $template = $self->{templates}{'MI_Makefile.PL'};
    $self->render($template, \%options);
}

sub Build_PL_guts {
    my $self = shift;
    my %options;
    @options{qw(main_module main_pm_file)} = @_;

    my $template = $self->{templates}{'Build.PL'};
    $self->render($template, \%options);
}

sub Changes_guts {
    my $self = shift;

    my $template = $self->{templates}{'Changes'};
    $self->render($template);
}

sub README_guts {
    my $self = shift;
    my %options;
    @options{qw(build_instructions)} = @_;

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

sub t_guts {
    my $self = shift;
    my %options;
    $options{modules} = [ @_ ];

    my %t_files;

    foreach (grep { /\.t$/ } keys %{$self->{templates}}) {
        my $template = $self->{templates}{$_};
        $t_files{$_} = $self->render($template, \%options);
    }

    return %t_files;
}

sub MANIFEST_guts {
    my $self = shift;
    my %options;
    $options{files} = [ sort @_ ];

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

sub ignores_guts {
    my $self = shift;

    my $template = $self->{templates}{ignores};
    $self->render($template);
}

# vi:et:sw=4 ts=4

1;