[Templates-cvs] cvs commit: TT3/lib/Template Context.pm
cvs@template-toolkit.org
cvs@template-toolkit.org
Fri, 10 Dec 2004 18:52:04 +0000
cvs 04/12/10 18:52:04
Modified: lib/Template Context.pm
Log:
* added Template::Compilers and Template::Provider
Revision Changes Path
1.8 +22 -3 TT3/lib/Template/Context.pm
Index: Context.pm
===================================================================
RCS file: /template-toolkit/TT3/lib/Template/Context.pm,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Context.pm 2004/12/10 14:53:34 1.7
+++ Context.pm 2004/12/10 18:52:04 1.8
@@ -16,7 +16,7 @@
# modify it under the same terms as Perl itself.
#
# REVISION
-# $Id: Context.pm,v 1.7 2004/12/10 14:53:34 abw Exp $
+# $Id: Context.pm,v 1.8 2004/12/10 18:52:04 abw Exp $
#
#========================================================================
@@ -25,8 +25,11 @@
use strict;
use warnings;
use Template::Resources;
+use Template::Compilers;
+use Template::Provider;
use Template::Resource::Template;
use Template::Scope;
+use Template::Utils;
use base qw( Template::Scope );
# providers can define a fetch($context, $item) method which expects a
@@ -36,11 +39,14 @@
use constant FETCH => 'fetch';
use constant GET => 'get';
-our $VERSION = sprintf("%d.%02d", q$Revision: 1.7 $ =~ /(\d+)\.(\d+)/);
+our $VERSION = sprintf("%d.%02d", q$Revision: 1.8 $ =~ /(\d+)\.(\d+)/);
our $DEBUG = 0 unless defined $DEBUG;
our $ERROR = '';
our $THROW = 'context';
+our $UTILS = 'Template::Utils';
our $RESOURCES = 'Template::Resources' unless defined $RESOURCES;
+our $COMPILERS = 'Template::Compilers' unless defined $COMPILERS;
+our $TEMPLATES = 'Template::Provider' unless defined $TEMPLATES;
our $EXCEPTION = 'Template::Exception' unless defined $EXCEPTION;
@@ -54,6 +60,9 @@
sub init {
my ($self, $config) = @_;
+ my $extract = $UTILS->hash_extract($config,
+ [qw( template plugin filter )]);
+
# copy all keys in
@$self{ keys %$config } = values %$config;
@@ -62,6 +71,16 @@
$self->debug("created resource: $self->{ resources }\n") if $DEBUG;
+ $self->{ compilers } = $config->{ compilers }
+ || $self->pkgvar( COMPILERS => $COMPILERS );
+
+ $self->{ templates } = $config->{ templates } || do {
+ my $templates = $self->pkgvar( TEMPLATES => $TEMPLATES );
+ $templates->new($extract->{ template })
+ || return $self->error('failed to create templates provider: ',
+ $templates->error());
+ };
+
return $self;
}
@@ -205,7 +224,7 @@
=head1 VERSION
-$Revision: 1.7 $
+$Revision: 1.8 $
=head1 COPYRIGHT