Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 69 lines (63 sloc) 1.968 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
This patch for Text::Template 1.45 adds support for the STRICT option.
This automatically prepends 'use strict' to your template code, but
still allows you to use variables defined by the HASH option.

--- lib/Text/Template.pm 2008-04-16 18:38:08.000000000 -0500
+++ lib/Text/Template.pm 2010-03-12 12:21:31.416024029 -0600
@@ -255,6 +255,7 @@
   my $fi_eval_package;
   my $fi_scrub_package = 0;
   my $fi_filename = _param('filename') || $fi_self->{FILENAME} || 'template';
+ my $fi_strict = _param('strict', %fi_a);
 
   my $fi_prepend = _param('prepend', %fi_a);
   unless (defined $fi_prepend) {
@@ -272,6 +273,7 @@
     $fi_eval_package = caller;
   }
 
+ my @fi_varlist;
   my $fi_install_package;
   if (defined $fi_varhash) {
     if (defined $fi_package) {
@@ -281,7 +283,12 @@
     } else {
       $fi_install_package = $fi_eval_package; # The gensymmed one
     }
- _install_hash($fi_varhash => $fi_install_package);
+ @fi_varlist = _install_hash($fi_varhash => $fi_install_package);
+ }
+
+ if ($fi_strict) {
+ $fi_prepend = "use vars qw(@fi_varlist);$fi_prepend" if @fi_varlist;
+ $fi_prepend = "use strict;$fi_prepend";
   }
 
   if (defined $fi_package && defined $fi_safe) {
@@ -441,6 +448,7 @@
     $hashlist = [$hashlist];
   }
   my $hash;
+ my @varlist;
   foreach $hash (@$hashlist) {
     my $name;
     foreach $name (keys %$hash) {
@@ -449,13 +457,23 @@
       local *SYM = *{"$ {dest}::$name"};
       if (! defined $val) {
  delete ${"$ {dest}::"}{$name};
+ my $match = qr/^.\Q$name\E$/;
+ @varlist = grep { $_ !~ $match } @varlist;
       } elsif (ref $val) {
  *SYM = $val;
+ push @varlist, do {
+ if (UNIVERSAL::isa($val, 'ARRAY')) { '@' }
+ elsif (UNIVERSAL::isa($val, 'HASH')) { '%' }
+ else { '$' }
+ } . $name;
       } else {
   *SYM = \$val;
+ push @varlist, '$' . $name;
       }
     }
   }
+
+ @varlist;
 }
 
 sub TTerror { $ERROR }
Something went wrong with that request. Please try again.