[Templates-cvs] cvs commit: TT3/lib/Template Provider.pm
cvs@template-toolkit.org
cvs@template-toolkit.org
Fri, 26 Mar 2004 10:57:17 +0000
cvs 04/03/26 10:57:17
Modified: lib/Template Provider.pm
Log:
* changed fetch() to get() and fetch_path() to get_path()
Revision Changes Path
1.4 +44 -43 TT3/lib/Template/Provider.pm
Index: Provider.pm
===================================================================
RCS file: /template-toolkit/TT3/lib/Template/Provider.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Provider.pm 2004/03/23 14:20:35 1.3
+++ Provider.pm 2004/03/26 10:57:16 1.4
@@ -18,7 +18,7 @@
# modify it under the same terms as Perl itself.
#
# REVISION
-# $Id: Provider.pm,v 1.3 2004/03/23 14:20:35 abw Exp $
+# $Id: Provider.pm,v 1.4 2004/03/26 10:57:16 abw Exp $
#
#========================================================================
@@ -26,14 +26,14 @@
use strict;
use warnings;
-use Template::Source;
use Template::Utils;
+use Template::Source;
use Template::Base;
use base qw( Template::Base );
use vars qw( $VERSION $ERROR $DEBUG $UTILS $SOURCE
$MAX_PATHS $STATIC $ID @CONFIG );
-$VERSION = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/);
+$VERSION = sprintf("%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/);
$ERROR = '';
$DEBUG = 0 unless defined $DEBUG;
$UTILS = 'Template::Utils';
@@ -66,7 +66,7 @@
}
# copy across any load_source flag
- $self->{ load_source } = $config->{ load_source };
+# $self->{ load_source } = $config->{ load_source };
return $self;
}
@@ -97,23 +97,23 @@
# };
}
+# NOTE: renamed fetch()/fetch_path() to get()/get_path()
#------------------------------------------------------------------------
-# fetch($name, \%options)
+# get($name, \%options)
#
-# Fetch a template document if it can be found in any of the locations
-# defined in the paths for this provider. Calls fetch_path() for each
-# path.
+# Fetch a template document from one of the locations defined in the
+# paths for this provider. Calls get_path() for each path.
#------------------------------------------------------------------------
-sub fetch {
+sub get {
my $self = shift;
my $name = shift;
my $args = @_ && UNIVERSAL::isa($_[0], 'HASH') ? shift : { @_ };
my $paths = $self->paths() || return;
my ($path, $opts, $item);
- $self->debug("fetch($name)\n") if $self->{ DEBUG };
+ $self->debug("get($name)\n") if $self->{ DEBUG };
foreach my $p (@$paths) {
if (UNIVERSAL::isa($p, 'ARRAY')) {
@@ -126,33 +126,30 @@
$path = $p;
$opts = $args;
}
- $self->debug("calling fetch_path($path, $name, $opts)\n")
- if $self->{ DEBUG };
- $item = $self->fetch_path($path, $name, $opts);
+ $item = $self->get_path($path, $name, $opts);
return unless defined $item;
last if $item;
}
- $self->debug("fetched $name: $item\n") if $self->{ DEBUG };
return $item
|| $self->decline("$name not found");
}
#------------------------------------------------------------------------
-# fetch_path($path, $name, \%options)
+# get_path($path, $name, \%options)
#
# Fetch a template document identified by $name, from a specific location
# provided as $path.
#------------------------------------------------------------------------
-sub fetch_path {
+sub get_path {
my ($self, $path, $name) = (shift, shift, shift);
my $opts = @_ && UNIVERSAL::isa($_[0], 'HASH') ? shift : { @_ };
my $file = $UTILS->file_path($path, $name);
- $self->debug("looking to fetch file: $file\n") if $self->{ DEBUG };
+ $self->debug("get_path($path, $name) => $file\n") if $self->{ DEBUG };
if (-r $file) {
# define document parameters
@@ -321,18 +318,6 @@
#------------------------------------------------------------------------
-# source(\%options)
-#
-# Create a new Template::Source object (or whatever 'source' is set to).
-#------------------------------------------------------------------------
-
-sub source {
- my $self = shift;
- $self->object( source => @_ );
-}
-
-
-#------------------------------------------------------------------------
# load($file)
#
# Method to load the template from the file or other resource identified
@@ -383,7 +368,19 @@
}
+#------------------------------------------------------------------------
+# source(\%options)
+#
+# Create a new Template::Source object (or whatever 'source' is set to).
+#------------------------------------------------------------------------
+
+sub source {
+ my $self = shift;
+ $self->object( source => @_ );
+}
+
+
1;
__END__
@@ -400,18 +397,19 @@
path => ['/home/abw/tt3', '/usr/local/tt3'],
});
- my $source = $provider->fetch('myfile')
+ my $source = $provider->get('myfile')
|| die $provider->error();
=head1 DESCRIPTION
+
+NOTE: The docs below might be lagging being the code slightly.
-This module implements a default provider for the Template Toolkit
-which is responsible locating templates in a file system and returning
-Template::Source objects to represent the pertinent information
-relating to them. The Template::Provider module also acts as a base
-class from which other providers can be derived for fetching templates
-from other secondary storage systems or retrieveal mechanisms (e.g.
-database, http, etc.)
+This module implements a default provider for the Template Toolkit.
+It is responsible for locating and loading templates in a file system
+and returning information pertaining to them. The Template::Provider
+module also acts as a base class from which other providers can be
+derived for fetching templates from other secondary storage systems or
+retrieveal mechanisms (e.g. database, http, etc.)
=head1 METHODS
@@ -490,19 +488,19 @@
Returns the unique identifier for the provider, either provided as a
constructor parameter or generated automatically.
-=head2 fetch($name, \%options)
+=head2 get($name, \%options)
Fetch a template matching the first argument, $name. This method
-calls C<fetch_path()> for each path defined in the C<path> list.
+calls C<get_path()> for each path defined in the C<path> list.
- my $source = $provider->fetch('wibble')
+ my $source = $provider->get('wibble')
|| die $provider->error();
-=head2 fetch_path($path, $name, \%options)
+=head2 get_path($path, $name, \%options)
Fetch a named template from a specific path, given by the first argument.
- my $source = $provider->fetch_path('/home/abw/templates', 'wibble')
+ my $source = $provider->get_path('/home/abw/templates', 'wibble')
|| die $provider->error();
=head2 path()
@@ -543,13 +541,16 @@
Cons: make the provider dependant on the whole architecture, rather
than a simple "leaf node".
+ANSWER: yes and no. Providers can have either a fetch() method which
+gets the context, and/or a get() method which doesn't
+
=head1 AUTHOR
Andy Wardley E<lt>abw@wardley.orgE<gt>
=head1 VERSION
-$Revision: 1.3 $
+$Revision: 1.4 $
=head1 COPYRIGHT