Dr. Mu has asked for the wisdom of the Perl Monks concerning the following question:
Subroutine::new is called as:
Loop::new is called as:my $newobject = Subroutine->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 ...".my $class = 'Loop'; my $newobject = $class->new($parent)
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:
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!sub edit { my $self = shift; $self->(child('atoms')->[0])->edit }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Inheritance Issues
by Tanktalus (Canon) on Jan 27, 2005 at 22:36 UTC | |
by Dr. Mu (Hermit) on Jan 27, 2005 at 23:01 UTC | |
by tinita (Parson) on Jan 28, 2005 at 14:27 UTC | |
by dragonchild (Archbishop) on Jan 28, 2005 at 14:44 UTC | |
by Dr. Mu (Hermit) on Jan 30, 2005 at 04:25 UTC |