This is because in the environment where you are calling the
server(),
$self doesn't have the object in it.
$self has the object in the
Business::OnlinePayment class because it follows the Perl standard for a method:
sub server {
my $self = shift;
...
}
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).
I suspect two things are happening in your code:
- You didn't use strict, or you just added a my $self; without knowing why you were doing it.
- You didn't instantiate a Business:OnlinePayment object, or if you did, you didn't call set_defaults with it, as opposed to on it (a regular subroutine call instead of a method call).
Remember: you aren't in the
Business::OnlinePayment namespace wen you create
set_defaults (although you could be, see below), so you need to call it like this:
my $payer = Business::OnlinePayment->new();
set_defaults($payer);
Your code
could add the
set_defaults method to the class dynamically by defining it as
sub Business::OnlinePayment::set_defaults {
... your code here ...
}
If you instantiate the
Business::OnlinePayment class with this subroutine defined, then you'll be able to say
my $payer = Business::OnlinePayment->new();
$payer->set_defaults();
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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.