in reply to Best Practice for Replacing Globals

This is hard to tell by a verbal description and without seeing an SSCCE.

Basically: The more you need to refactor, the riskier.

Some thoughts:

Cheers Rolf
(addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
Wikisyntax for the Monastery

  • Comment on Re: Best Practice for Replacing Globals

Replies are listed 'Best First'.
Re^2: Best Practice for Replacing Globals
by marto (Cardinal) on Apr 19, 2023 at 13:43 UTC
Re^2: Best Practice for Replacing Globals
by beaker121 (Novice) on Apr 19, 2023 at 15:42 UTC
    It's a large project with many files. I don't really know what you mean by replacing them with real lexicals as I don't see that as being possible, these values need to be used across the program as a whole. For example, I'm trying to move towards more OO approach and was thinking of having the user information (preferences, username after session has been validated etc.) in its own package.
      > I don't really know what you mean by replacing them with real lexicals

      If a package var is used only inside a single file, you can use a lexical without tieing it.

      > these values need to be used across the program as a whole.

      Hmm, as I said I need to guess to understand your situation.

      For instance one of your descriptions fits for constants. I can't see the need to change them in a modperl environment.

      And you may be able to go the inverse way, keep those package vars and tie them to a class which adapts to the modperl runtime environment by accessing its values in a lexical hash.

      Again plain guess work without you showing an SSCCE.

      Cheers Rolf
      (addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
      Wikisyntax for the Monastery

        Thank you, in the end I have refactored all the globals out into CGI::application params and a user object. The static behaviour ones are now using the CGI::application config plug in.