Not this way. You say use foo, then you call Foo->new - case matters.
It looks sort of like you're trying to do inheritance, which is usually done more like:
#!/usr/bin/perl -w
package foo;
sub new
{
my ($class, @stuff) = @_;
my $self = {};
# do stuf with $self and @stuff...
bless {}, $class;
}
sub do_something
{
my ($self, @parms) = @_;
print "in do_something: $self, @parms\n";
}
package bar;
# if foo is in another file, also say "use foo;" here
@ISA = qw/foo/;
# "use base qw( foo );" can be used in place of the preceding 2 lines
+in perl >= 5.004_04 (I think), certainly by 5.6.0.
sub do_something_else
{
my ($self, @parms) = @_;
print "in do_something_else, $self, @parms\n";
}
package main;
my $b = new bar;
$b->do_something('stuff');
$b->do_something_else('stuff2');
__END__
Results in:
in do_something: bar=HASH(0x804ca30), stuff
in do_something_else, bar=HASH(0x804ca30), stuff2
new and do_something, not defined in bar, still work because they are inherited from foo. do_something_else is defined in bar. so it works too.
All code given here is UNTESTED unless otherwise stated.
--Bob Niederman, http://bob-n.com |