in reply to Scope of required modules
Each package doesn't have its own instance of perl. When a module requires C, the C namespace is populated. Requiring a module is not that different from saying "our $C::foo" Any code that asks to see the C namespace can see every variable within it.
Q: Can A access B content without requiring B directly?
Yes, but don't do that. It will be a pain for future programmers to figure out what's going on.
Q: If a module is required twice, is there any mechanism like in C++ that can check if a module is required twice and in that case skip any redundant require's ?
See "perldoc -f require" Require records the modules it finds in %INC and will ignore redundant requests.
Q: Is the last require of A to D redundant? i.e. Can A access D without it?
No, it tells the next programmer that A intends to use D and keeps them from murdering you when they can't figure out where these D::foo methods are coming from. And if C ever changes its internal format to stop using D the code will still work.
|
|---|