As others have said, document what your module does and trust the user. However, it is worth considering the philosophical difference between a class call and an object call. If your Perl module provides a way to create objects, many of the methods in this class can rely on data specific to an individual object. This is probably the most common way to call methods: as soon as you have an object, you simply do $object->method(…) . However, it is likely that some methods of the class are common and do not need data from a specific object. They are often called using the package name, and this is most often encountered when calling the new() method, for example LWP::UserAgent->new() .
Conveniently, Perl allows you to treat these two cases the same way, using something like my $self = shift; at the beginning of the method: if the method is called on the object, $self gets the value of the reference to the object, if called in the class, $self gets the name of the package.
Even if the method is called in the class, so $self contains the name of the package, you can still call other methods in this package in the same way by doing $self->method(…) . Then this is compatible with calling the original method on a specific object, so everything sticks together.
As one example, the Perl Math :: BigInt package includes quite a few methods, some of which are designed to be called on the package (class) itself (for example, new() ), some of which must be called on separate objects (for example, round() ), and some on any (e.g. accuracy() ).
Moral: it must be consistent with the functionality of the method as to whether it is capable of a reasonable meaning. It is reasonable to assume that any method is invoked with the expectation that it will do what you advertise. However, it is not required that the method call be on the object when it makes sense to call this method on the class itself.
source share