in reply to Re^2: Overrides in a Package
in thread Overrides in a Package
A Perl method call automatically adds the object that the method is being called on to the beginning of the parameter list. This allows the method to address things in the object (for instance, the server name).sub server { my $self = shift; ... }
I suspect two things are happening in your code:
Your code could add the set_defaults method to the class dynamically by defining it asmy $payer = Business::OnlinePayment->new(); set_defaults($payer);
If you instantiate the Business::OnlinePayment class with this subroutine defined, then you'll be able to saysub Business::OnlinePayment::set_defaults { ... your code here ... }
as defining the sub with a fully-qualified name automatically adds it to the namespace, and if it's in the namespace, Perl will treat it as if it were a method defined in the Business/OnlinePayment.pm file, no matter where it was actually defined. I would recommend you not do this unless you comment it extensively! The next person along will not be expecting this, and if you invoke $payer->set_defaults() he or she will expect to find that in Business/OnlinePayment.pm and will confused and irritated if it is not there but works.my $payer = Business::OnlinePayment->new(); $payer->set_defaults();
|
|---|