base(3pm)
π base(3pm) β like, the Perl Programmers Reference Guide one π
okay so bestie, this is base, from the Perl Programmers Reference Guide, and it's about establishing an ISA relationship with base classes at compile time. yes that's the whole name, we're keeping it, periodt.
β¨ SYNOPSIS β¨
package Baz;
use base qw(Foo Bar);
like, that's it. that's the whole vibe. π¦
πΈ DESCRIPTION πΈ
okay so first thing, real talk: unless you're using the fields pragma, this module is discouraged β as in, consider using the lighter-weight parent instead. ngl, parent is kind of the moment. π
but what does base even do? it lets you both load one or more modules and set up inheritance from those modules at the same time. two things, one line, main character energy. β¨
roughly similar in effect to this whole thing:
package Baz;
BEGIN {
require Foo;
require Bar;
push @ISA, qw(Foo Bar);
}
so when base tries to require a module, it will not die if it can't find the module's file β cute β but it will die on any other error. π
after all that, should your base class be empty, containing no symbols, base will die. and weirdly that's actually useful! it's for inheriting from classes in the same file as yourself but 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, but because Foo defines a symbol (that exclaim subroutine), base will not die when the require fails to load Foo.pm. iconic behavior, honestly. π
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. π« see fields for a description of this feature.
also important: the base class' import method is not called. like, not at all. don't @ me.
π₯ DIAGNOSTICS π₯
Base class package "%s" is empty.base.pmwas unable to require the base package, because it was not found in your path. πClass 'Foo' tried to inherit from itselfattempting to inherit from yourself generates a warning. yeah bestie, self-inheritance is not the flex you think it is π
package Foo;
use base 'Foo';
β HISTORY β
this module was introduced with Perl 5.004_04. vintage. π
π¦ CAVEATS π¦
due to the limitations of the implementation, you must use base before you declare any of your own fields. like, before. not after. order matters, iykyk. β οΈ
π SEE ALSO π
fields
and that's the tea, bestie π β this was base(3pm) from perl v5.42.3, dated 2026-11-03. go forth and inherit responsibly, ily π«Άβ¨
π¦ where this page comes from
- alpine 3.24: perl-doc 5.42.3-r0 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms