package FindProvider; use strict; use base qw(Template::Provider); use Template::Constants qw(STATUS_DECLINED); use Cwd qw(); use File::Basename; sub fetch { my ($self,$filename) = @_; if (ref $filename or index($filename,'..') >= 0 or index($filename,'/') >= 0) { return $self->SUPER::fetch($filename); } my $path = ${$self->paths()}[0]; my $cwd = Cwd::getcwd(); while (index($cwd,$path) ==0) { # only recurse if current directory is in the first path if (-f "$cwd/$filename") { return $self->SUPER::fetch("$cwd/$filename"); } $cwd =~ s#/[^/]+/?$##; } return undef,STATUS_DECLINED; } 1;