App-DuckPAN

 view release on metacpan or  search on metacpan

lib/App/DuckPAN/TemplateDefinitions.pm  view on Meta::CPAN

package App::DuckPAN::TemplateDefinitions;
our $AUTHORITY = 'cpan:DDG';
# ABSTRACT: Parse the template definitions file to create templates and template sets
$App::DuckPAN::TemplateDefinitions::VERSION = '1021';
use Moo;

use Try::Tiny;
use Path::Tiny;
use YAML::XS qw(LoadFile);

use App::DuckPAN::Template;
use App::DuckPAN::TemplateSet;

use namespace::clean;

has templates_yml => (
	is       => 'ro',
	required => 1,
	default  => sub { path('template', 'templates.yml') },
	doc      => 'Path to the YAML file with template definitions',
);

has _templates_data => (
	is       => 'rwp',
	init_arg => undef,
	doc      => 'Raw template definitions read from the template definitions file',
);

has _template_map => (
	is       => 'ro',
	lazy     => 1,
	builder  => 1,
	init_arg => undef,
	doc      => 'Hashref of tempate name => App::DuckPAN::Template instances ' .
	            'built from the templates_yml file',
);

sub _build__template_map {
	my $self = shift;
	my $template_root = path($self->templates_yml)->parent;
	my $data = $self->_templates_data->{templates};
	my %template_map;

	for my $name (keys %$data) {
	    my $template_data = $data->{$name};

	    my $template = App::DuckPAN::Template->new(
	        name          => $name,
	        label         => $template_data->{label},
	        input_file    => path($template_root, $template_data->{input}),
	        output_file   => path($template_data->{output}),
	    );

	    $template_map{$name} = $template;
	}

	return \%template_map;
}

has _template_sets => (
	is      => 'ro',
	builder => 1,
	lazy    => 1,
	doc     => 'hashref of template set name to App::DuckPAN::TemplateSet instances ' .
	           'built from the templates_yml file',
);



( run in 0.965 second using v1.01-cache-2.11-cpan-39bf76dae61 )