The UNIVERSAL Package
Learn about the built-in UNIVERSAL package, the ancestor of all other packages.
We'll cover the following...
Perl’s built-in UNIVERSAL package is the ancestor of all other packages—it’s the ultimate parent class in an object-oriented sense. UNIVERSAL provides a few methods for its children to use, inherit, or override.
The VERSION() method
The VERSION() method returns the value of the $VERSION variable of the invoking
package or class. If we provide a version number as an optional parameter,
the method will throw an exception if the queried $VERSION is not equal to or
greater than the parameter.
Given a HowlerMonkey module of version 1.23, its VERSION() method behaves as
follows:
package HowlerMonkey {our $VERSION = 1.23;use Moose#...}my $hm = HowlerMonkey->new;say HowlerMonkey->VERSION; # prints 1.23say $hm->VERSION; # prints 1.23say $hm->VERSION( 0.0 ); # prints 1.23say $hm->VERSION( 1.23 ); # prints 1.23say $hm->VERSION( 2.0 ); # exception!
There’s little reason to override VERSION().
The DOES() method
The DOES() method supports the use of roles in programs. Pass it an invocant and the name of a role, and the method will return true if the ...