Well, as far as making it impossible to subclass, no, I don't think that's doable. However making things difficult is easy. (isn't it always?) Suppose you have a method selfcheck, that checks the species of itself before running each other method (and at destruction):
package Foo::Bar; my @lineage = ('Mom', 'Dad'); @ISA = (@lineage); sub selfcheck { die "You can\'t change who I am." unless __PACKAGE__ eq 'Foo::Bar'; map { die "You can\'t change who my parents are." unless $lineage[$_] eq + $ISA[$_] } (0..(scalar @ISA - 1)); } sub DESTROY { $self->Foo::Bar::selfcheck; } sub method_name { my $self=shift; $self->Foo::Bar::selfcheck; # method stuff here } sub method_name2 { $self->Foo::Bar::selfcheck; # method stuff here }
Now, you can overload all methods in the child class, but if you do you aren't really subclassing. You might as well subclass an anonymous hash. If you don't cover all bases, then the first time an inherited method is called, the program will die uglily and point out to the foolish programmer the error of his ways.

- d


In reply to Re: A class that cannot be subclassed. by dynamo
in thread A class that cannot be subclassed. by kyle

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.