I have an object class,
Loop, which inherits from
AtomBlock, which inherits from
Atom. There is another object class,
Subroutine which uses the same inheritance chain as
Loop. In each case, the inheritance chain is defined with the
use base pragma. In
Atom.pm there's an object method called "
child", which is used to populate the various objects with subordinate objects. Both
Loop.pm and
Subroutine.pm call
child as an object method, as part of their
new class methods.
Subroutine::new is called as:
my $newobject = Subroutine->new($parent)
Loop::new is called as:
my $class = 'Loop';
my $newobject = $class->new($parent)
Both calls are made from the same module,
Worksheet.pm.
Subroutine::new works just fine, but
Loop::new returns an error, "Undefined subroutine &Loop::child ...".
I realize that use base is a compile-time pragma, so I've made sure to include a use Loop; in both the main program and Worksheet.pm. But what else have I overlooked?
Update:
Oh gosh, this is embarassing. I'm glad I'm among friends! Anyway, the invocation of child that caused the error cited was not in Loop::new, but later in Loop::edit, viz:
sub edit {
my $self = shift;
$self->(child('atoms')->[0])->edit
}
The parenthesis to the left of
child should be to the left of
$self; or else the parens should be left out entirely: they're superfluous. With the change, the program worked. Without it,
child was not being invoked as a method of
$self, but as a simple subroutine in
Loop.pm. Hence the error. My apologies for wasting the monks' time on this one!
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.