Config-TT2
view release on metacpan or search on metacpan
lib/Config/TT2.pm view on Meta::CPAN
use strict;
use warnings;
package Config::TT2;
use Template;
use Try::Tiny;
use Carp qw(croak);
our $VERSION = '0.53';
=head1 NAME
Config::TT2 - Reading configuration files with the Template-Toolkit parser.
=head1 ABSTRACT
Define configuration files in the powerful, flexible and extensible Template-Toolkit syntax.
=cut
sub new {
my $class = shift;
# params as HASH or HASHREF?
my $params = defined( $_[0] ) && ref( $_[0] ) eq 'HASH' ? shift : {@_};
#
# Warn for unsupported Template and Template::Service params.
# Our entry level is Template::Context, see Template::Manual::Internals
#
my @unsupported = qw(
PRE_PROCESS
PROCESS
POST_PROCESS
WRAPPER
AUTO_RESET
DEFAULT
OUTPUT
OUTPUT_PATH
ERROR
ERRORS
);
foreach my $unsupported (@unsupported) {
croak "Option '$unsupported' not supported\n"
if exists $params->{$unsupported};
}
#
# DEFAULTS, see Template::Manual::Config
#
my $defaults = {
STRICT => 1,
ABSOLUTE => 1,
RELATIVE => 1,
CACHE_SIZE => 0,
};
# override defaults by params
my $self = bless { _PARAMS => { %$defaults, %$params } }, $class;
my $tt = Template->new( $self->{_PARAMS} ) || croak "$Template::ERROR\n";
# our entry level into TT2 is Template::Context to get the stash back
$self->context( $tt->service->context );
( run in 3.177 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )