[Templates-cvs] cvs commit: TT3/lib/Template Source.pm
cvs@template-toolkit.org
cvs@template-toolkit.org
Fri, 26 Mar 2004 14:10:19 +0000
cvs 04/03/26 14:10:19
Modified: lib/Template Source.pm
Log:
* changed code() to code_ref() and text() to text_ref() (both of which
return scalar refs) and then re-wrote text() and code() to call
text_ref() and code_ref() respectively and re-reference the text returned
Revision Changes Path
1.3 +38 -14 TT3/lib/Template/Source.pm
Index: Source.pm
===================================================================
RCS file: /template-toolkit/TT3/lib/Template/Source.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Source.pm 2004/03/25 14:28:15 1.2
+++ Source.pm 2004/03/26 14:10:18 1.3
@@ -17,7 +17,7 @@
# modify it under the same terms as Perl itself.
#
# REVISION
-# $Id: Source.pm,v 1.2 2004/03/25 14:28:15 abw Exp $
+# $Id: Source.pm,v 1.3 2004/03/26 14:10:18 abw Exp $
#
#========================================================================
@@ -30,7 +30,7 @@
use base qw( Template::Base );
use vars qw( $VERSION $DEBUG $ERROR $LIFE $COMPONENT );
-$VERSION = sprintf("%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/);
+$VERSION = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/);
$DEBUG = 0 unless defined $DEBUG;
$ERROR = '';
$COMPONENT = 'Template::Component';
@@ -183,13 +183,13 @@
#------------------------------------------------------------------------
-# text()
+# text_ref()
#
# Return the source text if already defined, or go and ask the provider
# to load it.
#------------------------------------------------------------------------
-sub text {
+sub text_ref {
my $self = shift;
my $args = @_ && UNIVERSAL::isa($_[0], 'HASH') ? shift : { @_ };
@@ -207,9 +207,15 @@
};
}
+sub text {
+ my $self = shift;
+ my $text = $self->text_ref() || return;
+ return $$text;
+}
+
#------------------------------------------------------------------------
-# code(\%args)
+# code_ref(\%args)
#
# Return the compiled source code if already defined, or fetch the text
# and ask a compiler to compile it. In this case, a reference to a
@@ -217,14 +223,14 @@
# a suitable compiler can be retrieved.
#------------------------------------------------------------------------
-sub code {
+sub code_ref {
my $self = shift;
my $args = @_ && UNIVERSAL::isa($_[0], 'HASH') ? shift : { @_ };
return $self->{ code } ||= do {
$self->debug("compiling document: $self->{ name }\n") if $self->{ DEBUG };
- my $text = $self->text($args) || return;
+ my $text = $self->text_ref($args) || return;
my $context = $args->{ context } || $self->{ context }
|| return $self->error('no context defined to compile code');
@@ -243,6 +249,12 @@
}
+sub code {
+ my $self = shift;
+ my $code = $self->code_ref() || return;
+ return $$code;
+}
+
#------------------------------------------------------------------------
# component(\%args)
@@ -253,7 +265,7 @@
sub component {
my $self = shift;
- my $code = $self->{ code } || $self->code(@_) || return;
+ my $code = $self->{ code } || $self->code_ref(@_) || return;
my $component;
if (UNIVERSAL::isa($code, 'SCALAR')) {
@@ -554,15 +566,27 @@
$cache->store($source->id(), $source)
if $source->option('cache');
+=head2 text_ref()
+
+Returns the source text as a reference to a scalar. The text may
+either be pre-defined as a constructor option, or will be fetched from
+the source provider (if defined).
+
=head2 text()
+
+Method of convenience which calls text_ref() and then de-references
+the text returned.
+
+=head2 code_ref(\%options)
-Returns the text defined as a constructor option or calls on the provider
-(if defined) to load it on demand.
+Returns the compiled Perl code for the template as a reference to a scalar.
+The code may be provided as a constructor option or will be generated by
+calling on the appropriate compiler to compile it.
-=head2 code(\%options)
+=head2 code()
-Returns the compiled Perl code for the template, provided as a constructor
-option or generated by calling on the appropriate compiler to compile it.
+Method of convenience which calls code_ref() and then de-references
+the text returned.
=head2 component(\%options)
@@ -582,7 +606,7 @@
=head1 VERSION
-$Revision: 1.2 $
+$Revision: 1.3 $
=head1 COPYRIGHT