On Mon, Jul 08, 2002 at 09:33:35AM -0400, darren chamberlain wrote: > I made a few patches over the weekend; three for Template, one for > Template::Provider, and one for Template::Stash.
Excellent! Thanks, Darren. All but one of the patches look fine to me. This is the questionable one: > Maybe specify a flag on an INCLUDE_PATH like: > INCLUDE_PATH => '/usr/web/tt2/lib/+' or '/usr/web/tt2/lib/-' > where the '+' is 'walkdown' (from root to leaf) and '-' is > 'walkup' (from leaf to root) based on the current template > location. There was some discussion on the mailing list about this and concerns were raised that it was too much magic, and perhaps not the best way of implementing it. http://www.tt2.org/pipermail/templates/2001-October/001944.html I should have updated the TODO list to reflect this long ago. Apologies for not doing so. Anyway, having given it some thought, I now believe the simplest and best approach is to allow INCLUDE_PATH to be passed a subroutine, or an object which implements a method for generating a list of paths. This is in addition to regular path strings, of course. INCLUDE_PATH => [ '/home/abw/templates', \&my_path_generator_sub, $my_path_generator_object ], Then we modify the loop within Template::Provider::_fetch_path() from: foreach $dir (@{ $self->{ INCLUDE_PATH } }) { next unless $dir; $path = "$dir/$name"; ... } to something like: @paths = @{ $self->{ INCLUDE_PATH } }; while (@paths) { $dir = shift @paths || next; if (ref $dir eq 'CODE') { push(@paths, &$dir()); next; } elsif (UNIVERSAL::can($dir, 'paths')) { push(@paths, $dir->paths()); next; } else { $path = "$dir/$name"; } ... } This should provide a generic solution for any kind of path walking stategy one may require. I need to think a little more about any particular strategy we add, especially one that changes the existing meaning of INCLUDE_PATH, but for now it should make it possible to get these things working and experiment to see what works. I'll add something like this to Template::Provider, have a play with it, and report back. As for the other patches, I'm happy to apply them, or you can go ahead and commit them yourself. I've added you to the CVS writers file (same username/password as the other repository). BUT.... if you do apply them yourself, don't forget to update: * docsrc/src/Manual/Variables.tt2 (add uniq vmethod) * docsrc/lib/option/output (output to array) * docsrc/src/Release/Changes.tt2 (your changes) Cheers A
