Well, my first thought is: you cant do this. period.

The reason being is anyone, anywhere can do

my $x=bless {},"My::B";
and it doesnt matter what else you have done or do.

Perls philosophy is "Id prefer you stay out of my living room because I ask you to, not because I have a shotgun." so you arent allowed a shotgun.

But i was thinking you could do something simple, a basic caller check to see if the calling sub originated in a module that @ISA "My::A". If it isnt then you could fail, if it is then everything is happy. Something like the following untested snippet

croak "Must be called from a My::A class or subclass." unless UNIVERSAL::isa(scalar caller(),"My::A");
Apologies if im not communicating very well, im coming down with the flu.

<STONG>UPDATE
I think I sortof answered a question that Masem wasnt asking. :-) If the issue is regarding an aesthetic descion in how to indicate usage through form I would go (and have often done so) with having the 'private' class defined in the same file as the 'public', but at the end of file. Perhaps following some kind of comment that indicates that the contained classes are 'private' utility classes employed by the 'public' one.

Yves / DeMerphq
--
When to use Prototypes?
Advanced Sorting - GRT - Guttman Rosler Transform


In reply to Re: Private Classes - Same or Separate Files? by demerphq
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.