Feature Request: throwing an exception when assigning to the CONSTANTS hash

David Turland <[email protected]> Sat, 18 May 2013 15:43:18 +0100
Newsgroups gmane.comp.lang.perl.modules.template-toolkit
Message-ID <[email protected]>
Apologies: now with, hopefully, the correct subject !

Hi,
So this is the hack I have added which 'seems' to 'work':


--- Directive.orig.pm    2013-05-18 11:53:37.363955087 +0100
+++ Directive.pm    2013-05-18 11:52:43.627224944 +0100
@@ -250,6 +250,11 @@
      my ($self, $var, $val, $default) = @_;

      if (ref $var) {
+
+        if ( "\'constants\'" eq $var->[0]){
+          print "Tried to assign $val to  $var->[0] which is probably 
the CONSTANTS hash";
+          die " You might want to catch this?";
+        }
          if (scalar @$var == 2 && ! $var->[1]) {
              $var = $var->[0];
          }

Note : it is in Directives::assign (which could die) rather than 
Stash::set (which refused to die or throw)

Also, the hack:
-  is probably not in the best place,
-  does not check for CONSTANTS_NAMESPACE
-  does throw or die in an informative way (hence the print)
-  is not constrained to STRICT or DEBUG

Comments and suggestions welcome.

Regards,

David T