App::Scaffolder::Template - Represent a template for App::Scaffolder
version 0.002000
use Path::Class::Dir; use App::Scaffolder::Template; my $template = App::Scaffolder::Template->new({ name => 'name_of_the_template', path => [ Path::Class::Dir->new('/first/path/belonging/to/template'), Path::Class::Dir->new('/second/path/belonging/to/template'), ] }); my @files = $template->process({ target => Path::Class::Dir->new('target', 'directory'), variables => { variable_value => 'a variable value', } });
App::Scaffolder::Template represents a template. A template consists of one or more directories containing files that should be copied to a target directory when processing it. If a file has a .tt extension, it will be passed through Template before it is written to a target file without the .tt suffix. Thus the template
.tt
foo |-- subdir | |-- template.txt.tt | `-- sub.txt |-- top-template.txt.tt `-- bar.txt
would result in the following structure after processing:
output |-- subdir | |-- template.txt | `-- sub.txt |-- top-template.txt `-- bar.txt
The path of a file in the template may also contain variables, which are delimited by ___ and replaced with values from the variables passed to process:
___
variables
process
# Template file path: ___dir___/___name___.txt # Given $variables = { dir => 'directory', name => 'some_name' }, the # following file will be created in the target directory: directory/some_name.txt
This can be useful if parts of the output file path are not constant.
Constructor, creates new instance.
This method expects its parameters as a hash reference.
Name of the template.
Search path for files that belong to the template. If more than one file has the same relative path, only the first one will be used, so it is possible to override files that come 'later' in the search path.
Push another directory on the search path.
Getter for the template file search path.
The template file search path.
Getter for the name.
The name.
Process the template.
Target directory where the output should be stored.
Hash reference with variables that should be made available to templates.
By default, existing files will not be overwritten. Passing a truthy value for the overwrite parameter changes this.
overwrite
A list with the created files on succes, an exception otherwise.
Given a file from the template and some template variables, read and potentially process the file and return the content the resulting file should have.
This method expects positional parameters.
Input file from the template.
Variables that should be made available to the template.
The content for the corresponding target file.
Replace parts inside a Path::Class::File-based path that match ___<name>___ with a value from a hash.
___<name>___
Path to the file which may contain placeholders.
Hash reference with values that should replace the placeholders.
The processed file path.
Getter for the file that belong to the template.
A hash reference containing hash references with information about the files.
Manfred Stock <mstock@cpan.org>
This software is copyright (c) 2014 by Manfred Stock.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install App::Scaffolder, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::Scaffolder
CPAN shell
perl -MCPAN -e shell install App::Scaffolder
For more information on module installation, please visit the detailed CPAN module installation guide.