in reply to Dealing with abstract methods in Perl 5.8

I too am interested in making interface style classes more automated. I'm not a big fan of stuffing things in UNIVERSAL however.

If it were me implementing this, I'd make the Attribute::Abstract module the super class of the interface modules like so:

use Attribute::Abstract; BEGIN { our @ISA = qw[Attribute::Abstract]; }

That way you don't need to stuff anything into UNIVERSAL. Then, in Attribute::Abstract, I'd register all modules that use() it (via inheritance of an import()) and check their @ISA for Attribute::Abstract and cause death at compile time for non-overidden methods.

Of course this is all 100% conjecture. I'm not sure if it's possible, etc. But it's the direction I would go in if posed this particular problem.

Replies are listed 'Best First'.
Re^2: Dealing with abstract methods in Perl 5.8
by glasswalk3r (Friar) on Apr 25, 2007 at 13:28 UTC

    I'm not sure if I agree with you about putting the code into UNIVERSAL. Anyway, looks quite logical since is the kind of function that any superclass should use. Why do you think is not a good idea?

    Regarding the exception during compilation time, this would kill any module that generates code during execution time. Since we're talking about Perl after all, this is really a bad thing to do and I don't think is worth to do it to just receive a die because the programmer forgot to override a method.

    Alceu Rodrigues de Freitas Junior
    ---------------------------------
    "You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill