Skip to Main Content
Programming Perl, 3rd Edition
book

Programming Perl, 3rd Edition

by Larry Wall, Tom Christiansen, Jon Orwant
July 2000
Intermediate to advanced content levelIntermediate to advanced
1104 pages
35h 1m
English
O'Reilly Media, Inc.
Content preview from Programming Perl, 3rd Edition

use base

use base qw(Mother Father);

This pragma lets a programmer conveniently declare a derived class based upon the listed parent classes. The declaration above is roughly equivalent to:

BEGIN {
    require Mother;
    require Father;
    push @ISA, qw(Mother Father);
}

The use base pragma takes care of any require needed. When the strict 'vars' pragma is in scope, use base lets you (in effect) assign to @ISA without first having to declare our @ISA. (Since the use base pragma happens at compile time, it's best to avoid diddling @ISA on your own at run time.)

But beyond this, use base has another property. If any named base class makes use of the fields facility described under use fields later in this chapter, then the pragma initializes the package's special field attributes from the base class. (Multiple inheritance of field classes is not supported. The use base pragma raises an exception if more than one named base class has fields.)

Any base class not yet loaded will be loaded automatically via require. However, whether to require a base class package is determined not by the customary inspection of %INC, but by the absence of a global $VERSION in the base package. This hack keeps Perl from repeatedly trying (and failing) to load a base class that isn't in its own requirable file (because, for example, it's loaded as part of some other module's file). If $VERSION is not detected after successfully loading a file, use base will define $VERSION in the base package, setting it to the string ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Perl, 2nd Edition

Mastering Perl, 2nd Edition

brian d foy
Programming the Perl DBI

Programming the Perl DBI

Tim Bunce, Alligator Descartes
Perl in a Nutshell, 2nd Edition

Perl in a Nutshell, 2nd Edition

Nathan Patwardhan, Ellen Siever, Stephen Spainhour

Publisher Resources

ISBN: 0596000278Supplemental ContentErrata