in reply to OO semantics quandary

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.

Replies are listed 'Best First'.
Re: Re: OO semantics quandary
by smalhotra (Scribe) on Aug 16, 2002 at 22:02 UTC
    This sounds reasonable to me but ofcourse, it's up to us to provide suggestions guidance, and it's up to the author to decide whether a suggestion fits right with their code. So, belg4mit, let us know what you think.