I'd probably go with My::A::B or even My::A::_B [ because a leading "_" is standard Perl "style" for "private, please do not touch" ].

If the code is very small, I'd put it all in one file. If not, I'd put it in a separate file. [ Though size is not the only issue. If My::A::B's code is easier to maintain by keeping it in the same file or vice versa, then that is a good thing to base your decision on. I like keeping it in the same file as an indication that the code is private to My::A, but would expect that consideration is often outweighed. ]

I'd also put it in a separate file if there is a possibility of using My::A without ever using My::A::B. In that case I'd be sure to require My::A::B only when I decide I need it and never use it.

Personally, I'd hate to see code in My::A::B's constructor that tries to enforce that only code from My::A may call it. [ I tried to come up with a short justification for my feelings here, but failed. There are a lot of aspects to it. Such protection usually can be gotten around so you are just making it a little harder. So why waste the cycles? Why add that extra code that can be a source of bugs? I've had to work around bugs in modules and finding code like this that makes such work-arounds harder just makes you want to shoot the module author for spending that time writing that code rather than spending time on real improvements so maybe you wouldn't have to be working around the problem... ]

[ Updated. ]

        - tye (but my friends call me "Tye")

In reply to (tye)Re: Private Classes - Same or Separate Files? by tye
in thread Private Classes - Same or Separate Files? by Masem

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.