Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inheritance Structure

Status
Not open for further replies.

Rinoa666

Programmer
Mar 10, 2007
4
GB
Hi again, I'm trying to define an inheritance structure where each type of vehicle is in a separate module. Each module should give a simple print statement. Then the main package should print the details of each type of vehicle. So far I've got these two modules but after running the program can't locate Vehicle pm in @INC <INC contains:C:/Perl/lib C:/Perl/site/lib. How can I solve this problem?



Code:
package Vehicle;
use warnings;

sub new {
my ($class) = @_;
my $self = {
_engine} => "I have an engine.",
_wheel => "I have wheels.",
_door => "I have doors." 
};
bless $self, $class;
return $self; 
sub engine {
my ( $self, $engine ) = @_; 
$self->{_engine} = $engine;
return $self->{_engine};
}

sub wheel {
my ( $self, $wheels ) = @_;
$self->{_wheel} = $wheel;
return $self->{_wheel};
}

sub door {
my ( $self, $door ) = @_;
$self->{_door} = $door;
return $self->{_door};
}

sub print {
my ($self) = @_;
print( "Motor vehicle\n\n\n",$self->engine, $self->wheel, $self->door );
}

1; 


package Public;
use Vehicle;
use warnings;
our @ISA = qw(Vehicle);
sub new {
my ($class) = @_;
my $self = $class->SUPER::new();
$self->{_pub} = "I am public";
bless $self, $class;
return $self; 
}
sub pub {
my ( $self, $pub ) = @_; 
$self->{_pub} = $pub;
return $self->{_pub};
}

sub print {
my ($self) = @_;
$self->SUPER:rint;
}

1; 

[b]This is the main package.[/b]

#!/perl/local/bin/perl
use warnings;
use Public::Vehicle;

my $vehicle = Vehicle->create("_engine", "_wheel", "_door");

print "Motor vehicle class: ", $vehicle->_engine(), "\n";
print "Motor vehicle class: ", $vehicle->_wheel(), "\n";
print "Motor vehicle class: ", $vehicle->_door(), "\n";
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top