1base(3pm)              Perl Programmers Reference Guide              base(3pm)
2
3
4

NAME

6       base - Establish an ISA relationship with base classes at compile time
7

SYNOPSIS

9           package Baz;
10           use base qw(Foo Bar);
11

DESCRIPTION

13       Unless you are using the "fields" pragma, consider this module
14       discouraged in favor of the lighter-weight "parent".
15
16       Allows you to both load one or more modules, while setting up
17       inheritance from those modules at the same time.  Roughly similar in
18       effect to
19
20           package Baz;
21           BEGIN {
22               require Foo;
23               require Bar;
24               push @ISA, qw(Foo Bar);
25           }
26
27       When "base" tries to "require" a module, it will not die if it cannot
28       find the module's file, but will die on any other error.  After all
29       this, should your base class be empty, containing no symbols, "base"
30       will die. This is useful for inheriting from classes in the same file
31       as yourself but where the filename does not match the base module name,
32       like so:
33
34               # in Bar.pm
35               package Foo;
36               sub exclaim { "I can have such a thing?!" }
37
38               package Bar;
39               use base "Foo";
40
41       There is no Foo.pm, but because "Foo" defines a symbol (the "exclaim"
42       subroutine), "base" will not die when the "require" fails to load
43       Foo.pm.
44
45       "base" will also initialize the fields if one of the base classes has
46       it.  Multiple inheritance of fields is NOT supported, if two or more
47       base classes each have inheritable fields the 'base' pragma will croak.
48       See fields for a description of this feature.
49
50       The base class' "import" method is not called.
51

DIAGNOSTICS

53       Base class package "%s" is empty.
54           base.pm was unable to require the base package, because it was not
55           found in your path.
56
57       Class 'Foo' tried to inherit from itself
58           Attempting to inherit from yourself generates a warning.
59
60               package Foo;
61               use base 'Foo';
62

HISTORY

64       This module was introduced with Perl 5.004_04.
65

CAVEATS

67       Due to the limitations of the implementation, you must use base before
68       you declare any of your own fields.
69

SEE ALSO

71       fields
72
73
74
75perl v5.38.2                      2023-11-30                         base(3pm)
Impressum