Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

rhesa (5696)

  (email not shown publicly)

Journal of rhesa (5696)

Monday June 20, 2005
06:33 AM

"use base" revelation

[ #25287 ]

I always lived with the idea that "use base" was introduced with perl 5.6.0, and that we had to write

  require BaseClass;    # Thanks, merlyn :)
  use vars qw/@ISA/;
  @ISA = qw/BaseClass/;

to be compatible with older perls.

Today I learned ( that "use base" was introduced with Perl 5.004_04!

Is this an odd case of cargo cult? Does it mean we can stop doing the "use vars '@ISA'" thing now?

Who wants their OO code to be compatible with perls older than 5.005?

And where did I get this notion from that it only became available in 5.6?

Sometimes it seems that experience just means you're set in your ways....

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • use base qw(Foo Bar);
    is really the combination of: require Foo; require Bar; use vars qw(@ISA); @ISA = qw(Foo Bar); Don't forget those requires!
    • Randal L. Schwartz
    • Stonehenge
    • You're right, of course. But my question was, do we need to remember that? Can't we just "use base" for the rest of our lives and forget about that archaic way of subclassing?
      • is a mess. Occasionally it doesn't succeed in actually loading the parent module, and due to the way it's set up, it may not even complain about it too loudly, or at least not loud enough — maybe just a warning.

        I don't trust it. I prefer to call require or use myself, and consequentially, setting @ISA by hand.

        • If really is a mess, then surely it wouldn't have been included in the core distribution.

          No offence, but have you sent in a bug report with a patch, or even a failing test? I'm sure you must have hit an odd corner case. It's in the core, it's in broad use, so it must be okay for the majority of uses.
          • If really is a mess, then surely it wouldn't have been included in the core distribution.

            I wish that were true, but sadly, it's not. Quite a few core modules have big, big messes inside.

            • Well, thank you for bursting my bubble on that one ;)

              Any chance you could respond to my original questions? I'm really curious about it.
              • The problem, IMO, is the fact the base tries to solve two different problems in one swoop, with identical syntax. As a result: loading the module is optional. And all too often, it goes wrong. You get two types of cases where it goes wrong:
                1. Trying to load a module (and failing) where it shouldn't even have tried
                2. Not trying to load a module where it should have loaded it

                If you could steer base telling it exactly where you want it to load a module or not, then there would be far less of a problem. I person

  • I think you are confusing this with something else. The thing that was introduced with Perl 5.6 was our, so you can say

    require Foo;
    our @ISA = qw( Foo );

    instead of

    use vars qw( @ISA );
    require Foo;
    @ISA = qw( Foo );