I'm not a professional in Perl, but recently I had to implement inheritance with this language and got stuck.
Here is the screen shot of the sample (very simple) code and directory structure:
http://i.stack.imgur.com/nwv8t.png
The full error text is:
Can't locate Parent.pm in @INC (you may need to install the Parent module) (@INC contains: . /etc/perl /usr/local/lib/perl/5.18.2 /usr/local/share/perl/5.18.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.18 /usr/share/perl/5.18 /usr/local/lib/site_perl .) at lib/Child.pm line 2. BEGIN failed--compilation aborted at lib/Child.pm line 2. Compilation failed in require.
If there is some problem with the screen shot:
Directory tree:
.
├── lib
│ ├── Child.pm
│ └── Parent.pm
├── main.pl
└── MyProject.komodoproject
main.pl
#!/usr/bin/perl
use strict;
use warnings;
use lib::Child;
lib/Parent.pm
#!/usr/bin/perl
package lib::Parent;
sub new {
my ($class, $arg_for) = @_;
my $self = bless {}, $class;
$self->_init($arg_for);
return $self;
}
sub _init {
my ($self, $arg_for) = @_;
my %arg_for = %$arg_for;
$self->{prop1} = $arg_for{prop1};
$self->{prop2} = $arg_for{prop2};
}
1;
lib/Child.pm
#!/usr/bin/perl
use Parent;
package lib::Child;
@ISA = qw(Parent);
sub new {
my ($class, $arg_for) = @_;
my ($self) = Parent->new($arg_for);
$self->_init($arg_for);
return (bless ($self, $class));
}
sub _init {
my ($self, $arg_for) = @_;
my %arg_for = %$arg_for;
$self->{param1} = $arg_for{param1};
$self->{param2} = 'param2';
}
1;
Please advise. Thanks!
Can't locate package Parent for @lib::Child::ISA
, which is subtly different. – BorodinCan't locate Parent.pm in @INC (you may need to install the Parent module) (@INC contains: /etc/perl /usr/local/lib/perl/5.18.2 /usr/local/share/perl/5.18.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.18 /usr/share/perl/5.18 /usr/local/lib/site_perl .) at lib/Child.pm line 2. BEGIN failed--compilation aborted at lib/Child.pm line 2. Compilation failed in require at ./main.pl line 5. BEGIN failed--compilation aborted at ./main.pl line 5.
– a1111exe