Perl Object oriented
In Perl, modules and object-oriented programming go hand in hand. Not all modules are written in an object-oriented fashion, but most are. A couple of definitions are warranted here:
· An object is simply a referenced thingy that happens to know which class it belongs to.
· A class is simply a package that happens to provide methods to deal with objects.
· A method is simply a subroutine that expects an object reference (or a package name, for class methods) as its first argument.
To create an object (or instance of a class), use the class constructor. Usually the class constructor will be a function named “new,” but may be called “Create” for some Win32 modules. For example,
The constructor takes a list of arguments describing the properties of the object to be created (see the documentation of the module in question to determine what these should be) and returns a reference to the created object.
An example of a class constructor (internal to the module) is shown below:
Methods (subroutines expecting an object reference as their first argument) may be invoked in two ways:
Methods are simply declared subroutines in the package source file.