Anonymous Monk:   Note also that in a file containing multiple package namespaces, a block structure can be very useful to achieve complete lexical isolation within each package:
    package Foo { my $private; ...; ... }  # perl version 5.14+
    package Bar { my $private; ...; ... }
or (note required semicolon after package statement)
    { package Foo;  my $private; ...; ... }  # pre-5.14 perl
    { package Bar;  my $private; ...; ... }
(The pre-5.14 scoping will, of course, continue to work with version 5.14+.) And definitely make use of the life-simplifying parent module!

Update: And in any version of Perl 5, this scoping can be used to implement absolutely private package/class functions/methods:

package Foo { ... my @stuff = ( ... ); # initialized upon inclusion ... my $private_function = sub { ... }; ... my $private_class_method = sub { my $class = shift; ...; }; my $private_object_method = sub { my $obj_ref = shift; ...; }; ... $private_function->(@stuff); ... $class_name->$private_class_method(...); $object_reference->$private_object_method(...); ... }
(This assumes that all these separate packages are contained in a standard .pm module that is use-ed or require-ed in the, well, usual way so that phasing problems are eliminated — or at least minimized.) The naming is a bit misleading in that both the  $private_class_method and  $private_object_method methods can be invoked with either a class name or an object reference, although what you do with the class name/object reference therein is another story! But they're still private.

All this, it must be said, starts to sound like a real OO system, of which there are many thorough-going implementations in CPAN.


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


In reply to Re^2: Multiple Packages in a Module? by AnomalousMonk
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.