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
    haukex: ...the equivalent of use would be BEGIN { require test_v1; Foo->import(); Foo::Bar->import(); }.
    Actually, no. The equivalent would be BEGIN { require test_v1; test_v1->import; }.
      Actually, no. The equivalent would be BEGIN { require test_v1; test_v1->import; }.

      No, because I wrote "in the case you describe", which is that there is one file test_v1.pm with two packages, Foo and Foo::Bar (no mention of a package test_v1). The code I showed is the equivalent of splitting that one file into two (Foo.pm and Foo/Bar.pm) and useing them individually.

        Agreed. I seem to have had difficulties with identifying "in the case you describe" as splitting one file into two.