Rename Foo::Bar to Text::Figlet::Font. Create a class, Text::Figlet::Control. 'Text::Figlet' is just a namespace; it doesn't and shouldn't say anything about inheritance.

Now, assuming you've been a good boy and don't have any code that actually uses an object's class name for anything, you're almost home and dry. Just add a factory method to Text::Figlet. Something like the following

package Text::Figlet; use Text::Figlet::Font; use Text::Figlet::Control; sub new { my $proto = new; my $class = 'Font'; if ($_[0] =~ /Font|Control/i) { $class = ucfirst(shift); } $class = "Text::Figlet::$class"; $class->new(@_); }
There's an issue here with having to update the factory every time you add a class, but it could be worse. Hopefully by doing it this way none of your old code will break.

Also, bless that closure into a class, and give it a single method that calls the closure. Again, stuff that assumes it's a closure won't break, but you'll be able to add potentially useful methods without having to mess too much with the internals of the closure.


In reply to Re: OO semantics quandary by pdcawley
in thread OO semantics quandary by belg4mit

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.