in reply to Re^2: Import constants as scalar instead of bareword sub
in thread Import constants as scalar instead of bareword sub

Do you also disallow soft references? ${$foo} = 123; is just as dangerous. As for autocopying a function to a scalar, that's not hard to do with a generalized import function. Learn a little symbol table magic - it's good for the soul. :-)

My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

Replies are listed 'Best First'.
Re^4: Import constants as scalar instead of bareword sub
by powerman (Friar) on Nov 02, 2005 at 21:32 UTC
    Hm. This is Meditation, AFAIK, not Seekers of Perl Wisdom. I don't ask "is it possible to do some dark magic with symbol table using some generalized import()", I can do this without problems, as least I hope so. :) I ask "is it has sense to go this way"...
      Damian in PBP says to do so, using Readonly to enforce the constancy of it. I don't agree - I prefer constant, but that's because I do most of my code in an OO fashion where "use constant" creates an inheritable method for me and export only in rare circumstances. As for auto-converting "use constant" into Readonly variables for some other module ... it's violating the API of the module. I would do that only if it's broken, not because I don't like it.

      Of course, you could just define your own wrapper around the offender ...


      My criteria for good software:
      1. Does it work?
      2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?