Search⌘ K
AI Features

Overriding Methods

Explore how to override methods in Perl object-oriented programming with Moose. Understand using Moose’s override keyword to clearly express overrides and employ super to call parent methods. This lesson helps you manage method dispatch and inheritance effectively for maintainable Perl code.

Inheritance and method overriding

As with attributes, subclasses may override methods. Imagine a light that we can't extinguish:

Perl
package Glowstick {
use Moose;
extends 'LightSource';
sub extinguish {}
}

Calling extinguish() on ...