in reply to Multiple Packages in a Module?

If foo.pm defines both package Foo and Package Foo::Bar, all will be well if every program does use Foo; that is never, ever preceded by use Foo::Bar;, and if there is not by pure-accident a Foo/Bar.pm file anywhere in your filesystem. If there's a conflict in your package resolution, it can be a true headache to debug. Worse yet, your test cases might not be doing what you think they are!

Replies are listed 'Best First'.
Re^2: Multiple Packages in a Module?
by haukex (Archbishop) on Jun 25, 2018 at 20:52 UTC
    all will be well if every program does use Foo; that is never, ever preceded by use Foo::Bar;

    I disagree with the two underlined wordings. It's possible that the two definitions of package Foo::Bar don't conflict, and that the overlap may even be intentional, for example if package Foo needs to monkey-patch something into Foo::Bar. Granted, these cases may be rare, and the point that the packages might conflict is very valid, but the above wordings are just too absolute for my taste.

Re^2: Multiple Packages in a Module?
by AnomalousMonk (Archbishop) on Jun 25, 2018 at 21:10 UTC
    If foo.pm defines both package Foo and Package Foo::Bar, all will be well if every program does use Foo; that is never, ever preceded by use Foo::Bar; ...

    In the above case, a  use Foo::Bar; statement can never access a file  foo.pm (In Windose (sigh)) or  Foo.pm (in other, saner file systems).

    ... and if there is not by pure-accident a Foo/Bar.pm file anywhere in your filesystem. If there's a conflict in your package resolution ...

    If there's ambiguity or conflict in file name resolution ordering, then any use or require statement can latch onto the wrong .pm file; it has nothing to do with defining multiple package namespaces within a single .pm file.

    ... it can be a true headache to debug.

    True that, brother!


    Give a man a fish:  <%-{-{-{-<