[Templates-cvs] cvs commit: TT3/lib/Template/Tagset TT.pm
cvs@template-toolkit.org
cvs@template-toolkit.org
Wed, 10 Nov 2004 17:58:35 +0000
cvs 04/11/10 17:58:35
Added: lib/Template/Tagset TT.pm
Log:
* added Template::Tagset::TT which defines regular TT tags
Revision Changes Path
1.1 TT3/lib/Template/Tagset/TT.pm
Index: TT.pm
===================================================================
#========================================================================
#
# Template::Tagset::TT
#
# DESCRIPTION
# Tagset defining the default set of tags for Template Toolkit templates.
#
# AUTHOR
# Andy Wardley <abw@wardley.org>
#
# COPYRIGHT
# Copyright (C) 1996-2004 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.
#
# REVISION
# $Id: TT.pm,v 1.1 2004/11/10 17:58:35 abw Exp $
#
#========================================================================
package Template::Tagset::TT;
use strict;
use warnings;
use Template::Tag::Directive;
use Template::Tagset::TT::Interpolate;
use Template::Tagset;
use base qw( Template::Tagset );
our $VERSION = sprintf("%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/);
our $DEBUG = 0 unless defined $DEBUG;
our $ERROR = '';
our $TAGS = {
directive => 'Template::Tag::Directive',
interpolate => 'Template::Tagset::TT::Interpolate',
} unless defined $TAGS;
#------------------------------------------------------------------------
# pkgtags($config)
#
# Custom method to instantiate the default $TAGS for this package (or
# any subclass which may define a new $TAGS set), including the
# 'directive' tag and 'interpolate' tagset.
#------------------------------------------------------------------------
sub pkgtags {
my ($self, $config) = @_;
# $TAGS may be re-defined by subclass and can be a list or hash ref
my $pkgtags = $self->pkgvar( TAGS => $TAGS );
$pkgtags = UNIVERSAL::isa($pkgtags, 'HASH') ? { %$pkgtags }
: UNIVERSAL::isa($pkgtags, 'ARRAY') ? { @$pkgtags }
: return $self->error("invalid $TAGS package variable: $pkgtags");
my $pkglist = UNIVERSAL::isa($pkgtags, 'HASH') ? [ %$pkgtags ] : $pkgtags;
my $dirclass = $pkgtags->{ directive };
my $intclass = $pkgtags->{ interpolate };
my ($dirtag, $inttag);
# create new directive tag and interpolate tagset object unless we've
# already got references to objects for either of them
$dirtag = ref $dirclass ? $dirclass
: $dirclass->new( %$config )
|| return $self->error( "failed to create directive tag: ",
$dirclass->error() );
$inttag = ref $intclass ? $intclass
: $intclass->new( %$config,
enabled => $config->{ interpolate } ? 1 : 0 )
|| return $self->error( "failed to create interpolate tagset: ",
$intclass->error() );
return [ @$pkglist, directive => $dirtag, interpolate => $inttag ];
}
#------------------------------------------------------------------------
# directive($flag)
#
# Enables or disables the directive tag when an argument is passed, or
# returns the directive tag.
#------------------------------------------------------------------------
sub directive {
my $self = shift;
$self->switch( directive => @_ );
}
#------------------------------------------------------------------------
# interpolate($flag)
#
# Enables or disables the interpolate tag when an argument is passed, or
# returns the interpolate tag.
#------------------------------------------------------------------------
sub interpolate {
my $self = shift;
$self->switch( interpolate => @_ );
}
#------------------------------------------------------------------------
# tag_style()
# tag_start()
# tag_end()
#
# Delegate to the style(), start() and end() tags of the directive tag.
#------------------------------------------------------------------------
sub tag_style {
my $self = shift;
my $dir = $self->directive() || return;
return $dir->style(@_) || $self->error($dir->error());
}
sub tag_start {
my $self = shift;
my $dir = $self->directive() || return;
return $dir->start(@_) || $self->error($dir->error());
}
sub tag_end {
my $self = shift;
my $dir = $self->directive() || return;
return $dir->end(@_) || $self->error($dir->error());
}
1;
__END__
=head1 NAME
Template::Tagset::TT - default collection of TT tag objects
=head1 SYNOPSIS
TODO
=head1 DESCRIPTION
# TODO
=head1 METHODS
=head2 new()
# TODO
=head1 AUTHOR
Andy Wardley E<lt>abw@wardley.orgE<gt>
=head1 VERSION
$Revision: 1.1 $
=head1 COPYRIGHT
Copyright (C) 1996-2004 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.
=cut
# Local Variables:
# mode: perl
# perl-indent-level: 4
# indent-tabs-mode: nil
# End:
#
# vim: expandtab shiftwidth=4: