package MyParent;
use strict;
no strict "refs";
use Carp qw(carp croak);
our $VERSION = .01;
sub new {
my $class = shift;
bless {
something => "foo",
}, $class;
return $self;
}
sub parent_nifty_method1 {
print $_[0]->{something};
}
sub parent_nifty_method2 {
... pah ...
}
####
package MyParent::MyChild;
use strict;
no strict "refs";
use Carp qw(carp croak);
use parent qw(MyParent);
our @ISA = qw(MyParent);
our @EXPORT = qw( method_a method_b );
my $VERSION = .01;
sub new {
my $class = shift;
my $this = bless {}, $class;
my( $parent ) = @_;
$this->{PARENT} = $parent;
return $this;
}
sub child_method_a {
#read parent variable, not change it
print MyParent->{something};
}
sub child_method_b {
... incredibly cool stuff ...
}
####
script_to_change_the_world.pl
#!/usr/bin/perl
use MyParent;
use MyParent::MyChild;
use strict;
my $parentobject = MyParent->new();
$parentobject->method1;
#prints: Foo
#Now I want to access something or other in the MyChild, doing it this way (which is what inheritance means to me)
$parentobject->child_method_a;
#Prints: Foo
####
Can't locate object method "child_method_a" via package "MyParent" at script_to_change_the_world.pl line 14.