I don't know how you would do that for variables, but for subroutines, you could try AUTOLOAD. However, I wouldn't recommend it. If you are trying to migrate your code from the main namespace to more specialized namespaces, those "method not found" errors are your friends - they tell you that you have missed a dependency that maybe should be moved as well to the new namespace.
To be honest, I'm not sure I've understood your goal. You've moved code from the main namespace to more specialized namespaces, but you still want all of your variables and subs to refer to the main namespace? That doesn't make much sense to me. The normal reason for moving code and variables into namespaces is to provide better encapsulation.
Better encapsulation would mean studying the code to find out what routines call what other routines and variables. Then if a variable $X is only used by sub A(), sub B(), and sub C(), all of which are in namespace Foo, you would move $X to Foo. If sub Y() was also only used by routines in Foo, you would move sub Y() to the Foo namespace as well.
Perhaps you are trying to eventually transition your code to namespaces, and don't want everything to break in the short term? If so, it is better to do these changes incrementally and bottom up. Move one subroutine at a time over to the new namespace. Study its code and make a conscious decision about the namespace for each variable and subroutine consumed by the one you just moved. Does it belong in the new namespace? main? some third namespace?
Start with a low level routine that is essential private to the mega routine that you eventually want to move. When you have moved several routines and variables over to the new namespace, and the mega subroutine has only a handful of dependencies left in "main", then and only then, move the mega routine.
Also be aware that when you move routines to a new namespace, all of the consumers of the moved routine will now need to change their calls to refer to the new namespace (which won't be main). If there are a lot of routines calling X() or you don't have a good way of tracking down all of the callers of X(), you may want to think twice about moving sub X() to a new namespace.
Best, beth
In reply to Re: Checking more than just the current namespace for sub and var definitions
by ELISHEVA
in thread Checking more than just the current namespace for sub and var definitions
by willjones
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |