I'm using the Perl mod XML::SemanticDiff which can compare two XML documents. I want to write my own custom handlers but, being relatively new to Perl I'm at a loss as to how to do this.

I understand that handlers are nothing more than subroutines that get called when certain events take place. But I'm fuzzy on the implementation details on how these events call the methods in my code.

For instance, the basic implementation of this module starts with something like:

There are three kinds of handler subroutines (depending on how the library using them is designed):

Predefined name. Meaning, the library is designed to allways call a sub with a fixed name called "XYZ()" in a particular scenario. This is very tricky to get right in terms of "which namespace is searched for the sub with that name"? To address that problem, a more common approach is #2:

A custom diff-handler class with predefined method names. As you can see from XML::SemanticDiff documentation, this is the case with your library.

The class is often inheriting from some existing base handler class with default handlers that should be overritten by your custom subclass. Alternately, it merely needs to implement some/all predefined methods but doesn't have to inherit (the latter is the case here).

In case of XML::SemanticDiff, you tell the module what your custom handler is by giving it an object of the custom handler class: