in reply to Multiple Packages in a Module?
In Perl, there is no required/fixed relationship between the name of a file and which/how many packages it contains, just a "best practice" to put a package named e.g. Foo::Bar in a file Foo/Bar.pm, because many tools (and people) expect this. So I'd suggest sticking to that practice unless you've got a good reason (which you haven't explained yet).
use Modulename ...; is equivalent to BEGIN { require Modulename; Modulename->import(...) }, so in the case you describe (Update: by which I mean, merging a package Foo in Foo.pm with package Foo::Bar in Foo/Bar.pm into one file test_v1.pm), one way to do the equivalent of use would be BEGIN { require test_v1; Foo->import(); Foo::Bar->import(); }. This will attempt to load a file test_v1.pm from one of the paths in @INC if it hasn't been loaded yet (see require), and it will call those two packages' import methods.
However, by your mention of -norequire I'm guessing you're using the parent pragma, and OO can be a little trickier. It would be best if you could show a minimal code example, see Short, Self-Contained, Correct Example.
Further reading: In this node I wrote about the basics of importing from modules (in a slightly different context, but still applicable here), and I recommend a thorough read of perlmod.
Minor edits.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Multiple Packages in a Module?
by haj (Vicar) on Jun 25, 2018 at 20:33 UTC | |
by haukex (Archbishop) on Jun 25, 2018 at 20:45 UTC | |
by haj (Vicar) on Jun 25, 2018 at 21:08 UTC | |
by haukex (Archbishop) on Jun 25, 2018 at 21:32 UTC |