diff --git a/.github/workflows/testsuite.yml b/.github/workflows/testsuite.yml index cdbd04ee..12ce5ba0 100644 --- a/.github/workflows/testsuite.yml +++ b/.github/workflows/testsuite.yml @@ -153,7 +153,7 @@ jobs: - uses: actions/checkout@v6 - run: perl -V - name: Install cpm - run: cpanm -n App::cpm Carton::Snapshot + run: cpanm -n App::cpm Carton::Snapshot || cpanm -n App::cpm Carton::Snapshot - name: Install Dependencies run: cpm install -g --no-test --show-build-log-on-failure --cpanfile cpanfile.plugins - name: Makefile.PL diff --git a/lib/Template/Provider.pm b/lib/Template/Provider.pm index eed64461..4e175efd 100644 --- a/lib/Template/Provider.pm +++ b/lib/Template/Provider.pm @@ -565,34 +565,22 @@ sub _compiled_filename { sub _load_compiled { my ($self, $file) = @_; - # Implicitly Relative paths are not supported - # by "require" and invoke @INC traversal, where relative - # paths only traditionally worked prior to Perl 5.26 - # due to the presence of '.' in @INC - # - # Given load_compiled never wants to traverse @INC, forcing - # an absolute path for the loaded file and the INC key is - # sensible. - # - # NB: %INC Keys are always identical to their respective - # "require" invocations regardless of OS, and the only time - # one needs to care about slash direction is when dealing - # with Module::Name -> Module/Name.pm translation. + # Force absolute path to avoid any relative path ambiguity. my $fpath = File::Spec->rel2abs( $file ); return $self->error("compiled template missing path") unless defined $fpath; + # Untaint the path ($fpath) = $fpath =~ /^(.*)$/s; - # load compiled template via require(); we zap any - # %INC entry to ensure it is reloaded (we don't - # want 1 returned by require() to say it's in memory) - delete $INC{ $fpath }; - my $compiled; - eval { $compiled = require $fpath; }; - return $@ - ? $self->error("compiled template $fpath: $@") - : $compiled; + # Use do() instead of require() to load compiled templates. + # Unlike require(), do() doesn't consult or modify %INC, + # so we avoid the previous hack of deleting %INC entries + # to force reloads (see GH #177). + my $compiled = do $fpath; + return $self->error("compiled template $fpath: $@") + if $@; + return $compiled; } #------------------------------------------------------------------------