in reply to use base 'XYZ' and exporting

What's wrong with
package LikeOOModule; use base 'MyOOModule'; sub foo { my $self = shift; if ($self->mode == $self->OO_THIS) { ... } elsif ($self->mode == $self->OO_THAT) { ... } }

Solves the problem and allows for overloading, if necessary. Don't let the fact that it's currently a constant blind you to the fact that you may want to override it later. (Particularly in testing, I've found.)


  • In general, if you think something isn't in Perl, try it out, because it usually is. :-)
  • "What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?"

Replies are listed 'Best First'.
Re^2: use base 'XYZ' and exporting
by japhy (Canon) on May 29, 2005 at 16:57 UTC
    But that's why I'm using constants, because their values shouldn't change. The concept of constant folding disappears when you do what you showed.

    Still, I agree with other people that this is an easily broken system, and goes against the definition of base. So I think I'll suck it up and write MyOOClass->import and be done with it all.


    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart