Re: Method calling question...
by MeowChow (Vicar) on Apr 30, 2001 at 22:23 UTC
|
I don't see what the problem is:
package Base;
sub method1 {
# Insert code here
print "Called from class: ", shift, "\n";
};
package Foo;
@ISA = qw(Base);
package Bar;
@ISA = qw(Base);
package main;
foreach my $classname qw(Foo Bar) {
$classname->method1;
}
## Output ##
Called from class: Foo
Called from class: Bar
MeowChow
s aamecha.s a..a\u$&owag.print | [reply] [d/l] |
|
|
There's a reason I was using four files. If you have everything in one file, of course it works cause method1 is scoped within the file. When you have it across several files, it breaks down. :(
| [reply] |
|
|
It's not a scoping issue:
foreach my $classname qw(Foo Bar Oops) {
$classname->method1;
}
## output ##
Can't locate object method "method1" via package "Oops" at C:\Projects
+\GPerl\Test\2.pl line 16.
Called from class: Foo
Called from class: Bar
MeowChow
s aamecha.s a..a\u$&owag.print | [reply] [d/l] |
|
|
(tye)Re: Method calling question...
by tye (Sage) on Apr 30, 2001 at 22:43 UTC
|
I can think of a few reasons why this might fail.
First, I don't see any require Foo nor require Bar (or replace require with use).
Second, you can replace @ISA= qw(Base) with use base qw(Base) which has some advantages. But I have more important reasons for mentioning that: On file systems that ignore upper- vs. lower-case in file names, use Base could end up loading base.pm instead of Base.pm, which would also break your code.
-
tye
(but my friends call me "Tye")
| [reply] [d/l] [select] |
|
|
| [reply] |
|
|
tilly
btrott
jcwren
lhoward
MeowChow
BigJoe
Beatnik
Macphisto
jplindstrom
jlp
LD2
Kanji
isotope
kandinsky
batmonk
joee
koolade
UberGeek
prion
I'll get enough of these and start performing an intersection. | [reply] [d/l] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"On file systems that ignore upper- vs. lower-case in file names, use Base could end up loading base.pm instead of Base.pm..."
Uhm, no.
If the file system is case-insensitive, then Base.pm == base.pm.
-- Dave
| [reply] [d/l] |
|
|
| [reply] |