I like to write my code like so:

package Some::Module; our $VERSION = '0.1'; our @ISA = qw( Super::Module ); package Some::Module::YeWhoEnters; sub pfoo { # ... } sub xbar { my ( $foo, $bar ) = @_; # ... my $baz = pfoo( $bar ); # ... } sub Some::Module::new { my $class = shift; # ... return xbar( $_ ); }

This way, everything is in a private package by default, and things only get into the publically documented package only when explicitly declared to belong there. At the same time, file-level lexicals are in scope during all of the code, and I can call private functions without having to prefix them with fully qualified package names. This is decent encapsulation, since you cannot accidentally call private functions as methods on the blessed reference without tricks, and you cannot invoke them as functions without the ::YeWhoEnters moniker either.

It’s a bit annoying that this setup breaks the ->SUPER::foo notation in Perl because that is based on the compile-time package of a method, but then I use SUPER nowadays anyway which makes that a non-issue.

But note that it’s not really possible to make this work for private methods without defeating the encapsulation.

Makeshifts last the longest.


In reply to Re: Perl Privvies by Aristotle
in thread Perl Privvies by tlm

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.