When writing a Perl module, do I have to specifically check for an object instance in all my methods?
oop, perl
Solution
No. If your module features only the most minimal documentation, it should be clear from that that `do_your_job` is a method that needs to be called on an object. If someone wants to call that in some other way, it's his fault.
Of course, you could check whether the first parameter to your method is a blessed object. But this has at least two drawbacks: You lose a little bit of performance and you clutter your methods with code that really doesn't do anything promised by the method's name.
Problem
I'm writing a module that has several methods. Let's consider this : ``` package MyPackage; sub new { ... } sub do_your_job { ... } 1; ``` What is to stop someone calling `do_your_job` like `MyPackage->do_your_job` instead of `$obj->do_your_job` ? Do I need to check in every method that I'm receiving a reference as the first argument?