Template-Toolkit
view release on metacpan or search on metacpan
lib/Template/Provider.pm view on Meta::CPAN
#============================================================= -*-Perl-*-
#
# Template::Provider
#
# DESCRIPTION
# This module implements a class which handles the loading, compiling
# and caching of templates. Multiple Template::Provider objects can
# be stacked and queried in turn to effect a Chain-of-Command between
# them. A provider will attempt to return the requested template,
# an error (STATUS_ERROR) or decline to provide the template
# (STATUS_DECLINE), allowing subsequent providers to attempt to
# deliver it. See 'Design Patterns' for further details.
#
# AUTHORS
# Andy Wardley <abw@wardley.org>
#
# Refactored by Bill Moseley for v2.19 to add negative caching (i.e.
# tracking templates that are NOTFOUND so that we can decline quickly)
# and to provide better support for subclassing the provider.
#
# COPYRIGHT
# Copyright (C) 1996-2022 Andy Wardley. All Rights Reserved.
#
# This module is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# WARNING:
# This code is ugly and contorted and is being totally re-written for TT3.
# In particular, we'll be throwing errors rather than messing around
# returning (value, status) pairs. With the benefit of hindsight, that
# was a really bad design decision on my part. I deserve to be knocked
# to the ground and kicked around a bit by hoards of angry TT developers
# for that one. Bill's refactoring has made the module easier to subclass,
# (so you can ease off the kicking now), but it really needs to be totally
# redesigned and rebuilt from the ground up along with the bits of TT that
# use it. -- abw 2007/04/27
#============================================================================
package Template::Provider;
use strict;
use warnings;
use base 'Template::Base';
use Template::Config;
use Template::Constants;
use Template::Document;
use File::Basename;
use File::Spec;
use constant PREV => 0;
use constant NAME => 1; # template name -- indexed by this name in LOOKUP
use constant DATA => 2; # Compiled template
use constant LOAD => 3; # mtime of template
use constant NEXT => 4; # link to next item in cache linked list
use constant STAT => 5; # Time last stat()ed
use constant MSWin32 => $^O eq 'MSWin32';
our $VERSION = '3.106';
our $DEBUG = 0 unless defined $DEBUG;
our $ERROR = '';
# name of document class
our $DOCUMENT = 'Template::Document' unless defined $DOCUMENT;
# maximum time between performing stat() on file to check staleness
our $STAT_TTL = 1 unless defined $STAT_TTL;
# maximum number of directories in an INCLUDE_PATH, to prevent runaways
our $MAX_DIRS = 64 unless defined $MAX_DIRS;
# UNICODE is supported in versions of Perl from 5.007 onwards
our $UNICODE = $] > 5.007 ? 1 : 0;
my $boms = [
'UTF-8' => "\x{ef}\x{bb}\x{bf}",
'UTF-32BE' => "\x{0}\x{0}\x{fe}\x{ff}",
'UTF-32LE' => "\x{ff}\x{fe}\x{0}\x{0}",
'UTF-16BE' => "\x{fe}\x{ff}",
'UTF-16LE' => "\x{ff}\x{fe}",
];
# regex to match relative paths
our $RELATIVE_PATH = qr[(?:^|/)\.+/];
#========================================================================
# -- PUBLIC METHODS --
#========================================================================
#------------------------------------------------------------------------
# fetch($name)
( run in 0.730 second using v1.01-cache-2.11-cpan-71847e10f99 )