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.


In reply to Re: Multiple Packages in a Module? by haukex
in thread Multiple Packages in a Module? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.