base(3perl)
π base(3perl) β the Perl Programmers Reference Guide, but make it cute
okay bestie, gather round, because this one is the og "let me be your parent real quick" module π«Ά
β¨ NAME β¨
base β establish an ISA relationship with base classes at compile time. yes, at compile time. it's giving "we're doing this early and we're doing it on purpose" π
β¨ SYNOPSIS β¨
package Baz;
use base qw(Foo Bar);
look at her. two lines. she's already loaded Foo and Bar and made them your parents. iconique β¨
β¨ DESCRIPTION β¨
lowkey important heads-up first: unless you're using the fields pragma, please consider this module discouraged, in favor of the lighter-weight parent. she's the cooler, skinnier sister, ngl. π¦
so what does she actually do? she lets you both load one or more modules and set up inheritance from those modules at the same time. it's a two-for-one. it's a bundle deal. roughly similar in effect to this whole situation:
package Baz;
BEGIN {
require Foo;
require Bar;
push @ISA, qw(Foo Bar);
}
except way less typing, because obviously. π
here's the part where she gets quirky. when base tries to require a module, she will not die if she can't find the module's file β but she will die on any other error. so like, missing file? she's chill. other chaos? she's not chill. π
after all that, if your base class turns out to be empty, i.e. containing no symbols at all, then base will die. and honestly? that's a feature, bestie. it's useful for inheriting from classes that live in the same file as you, where the filename does not match the base module name. like so:
# in Bar.pm
package Foo;
sub exclaim { "I can have such a thing?!" }
package Bar;
use base "Foo";
see what's happening?? there is no Foo.pm anywhere. but because "Foo" defines a symbol β that exclaim subroutine right there β base will not die when the require fails to load Foo.pm. she peeked inside, saw a symbol, and was like "okay you're real, we're good." π
base will also initialize the fields if one of the base classes has it. but listen β multiple inheritance of fields is NOT supported. if two or more base classes each have inheritable fields, the base pragma will croak. like, full on frog noise, no mercy. πΈ see fields for a description of this feature.
also, tiny but important: the base class' import method is not called. not even a little. not even a wave. π
π DIAGNOSTICS π
Base class package "%s" is empty.βbase.pmwas unable torequirethe base package, because it was not found in your path. (nothing in your path, nothing in your file, nothing to inherit from. rip. π)Class 'Foo' tried to inherit from itselfβ attempting to inherit from yourself generates a warning. self-love is great, self-inheritance is not:
package Foo;
use base 'Foo';
like bestie I love the confidence but you cannot be your own parent π
π HISTORY π
this module was introduced with Perl 5.004_04. so she's vintage. she's an elder. she's been slaying since before you were born, fr fr. β
β οΈ CAVEATS β οΈ
due to the limitations of the implementation, you must use base before you declare any of your own fields. before. first. no negotiating. if you do it after, it's not gonna go how you want it to go. π
π SEE ALSO π
fields
and that's the whole page, bestie π written up for perl v5.44.0, dated 2026-10-17, and that footer is the source/version + date, so consider this your cute lil sign-off: stay inherited, stay iconic, and never inherit from yourself πΈππ§
π¦ where this page comes from
- arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms