[Templates-cvs] cvs commit: TT3/lib/Template/VObject Text.pm
cvs@template-toolkit.org
cvs@template-toolkit.org
Mon, 29 Mar 2004 17:31:31 +0100
cvs 04/03/29 16:31:31
Added: lib/Template/VObject Text.pm
Log:
* added Template::VObject::Text
Revision Changes Path
1.1 TT3/lib/Template/VObject/Text.pm
Index: Text.pm
===================================================================
#========================================================================
#
# Template::VObject::Text
#
# DESCRIPTION
# Virtual object providing providing methods for manipulating text.
#
# AUTHOR
# Andy Wardley <abw@wardley.org>
#
# COPYRIGHT
# Copyright (C) 1996-2004 Andy Wardley. All Rights Reserved.
# Copyright (C) 1998-2002 Canon Research Centre Europe Ltd.
# Copyright (C) 2004 Fotango Ltd.
#
# This module is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# REVISION
# $Id: Text.pm,v 1.1 2004/03/29 16:31:31 abw Exp $
#
#========================================================================
package Template::VObject::Text;
use strict;
use warnings;
use Template::VObject;
use base qw( Template::VObject );
use vars qw( $VERSION $DEBUG $ERROR $THROW $METHODS );
$VERSION = sprintf("%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/);
$DEBUG = 0 unless defined $DEBUG;
$ERROR = '';
$THROW = 'Text';
$METHODS = {
# ref/type methods
ref => __PACKAGE__->can('ref'),
type => \&type,
# converters
copy => \©,
hash => \&hash,
list => \&list,
text => \&text,
item => \&item,
# accessors
size => \&size,
length => \&length,
equals => \&equals,
# mutators (all non-destructive)
pop => \&pop,
push => \&push,
shift => \&shift,
unshift => \&unshift,
append => \&push,
prepend => \&unshift,
centre => \¢re,
center => \¢re, # for our American friends
left => \&left,
right => \&right,
format => \&format,
upper => \&upper,
lower => \&lower,
capital => \&capital,
capitals => \&capitals,
chop => \&chop,
chomp => \&chomp,
trim => \&trim,
collapse => \&collapse,
truncate => \&truncate,
chunk => \&chunk,
repeat => \&repeat,
remove => \&remove,
replace => \&replace,
match => \&match,
search => \&match,
split => \&split,
};
sub new {
my ($class, $text) = @_;
my $self = ref $text ? $text : \$text;
$class = ref $class || $class;
bless $self, $class;
}
#------------------------------------------------------------------------
# upper() [% text.upper %]
# lower() [% text.lower %]
#
# Return text in upper or lower case.
#------------------------------------------------------------------------
sub upper {
my $self = shift;
my $text = ref $self ? $self : \$self;
return uc $$text;
}
sub lower {
my $self = shift;
my $text = ref $self ? $self : \$self;
return lc $$self;
}
sub text {
my $self = shift;
return ref $self ? $$self : $self;
}
1;
__END__
=head1 NAME
Template::VObject::Text - text virtual object
=head1 SYNOPSIS
# TODO
=head1 DESCRIPTION
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.
Copyright (C) 1998-2002 Canon Research Centre Europe Ltd.
Copyright (C) 2004 Fotango Ltd.
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: