Inheritance



examples/perloop/employee01/script/person.pl
use strict;
use warnings;
use v5.10;

use Person;
use Employee;
use DateTime;

my $student = Person->new( name => 'Foo' );
say $student->name;     # Foo

my $programmer = Employee->new( name => 'Bar' );
say $programmer->name;  # Bar

examples/perloop/employee01/lib/Person.pm
package Person;
use strict;
use warnings;

sub new {
    my ($class, %args) = @_;

    my $self = \%args;

    bless $self, $class;

    return $self;
}

sub name {
    my ($self, $value) = @_;
    if (@_ == 2) {
        $self->{name} = $value;
    }

    return $self->{name};
}

1;

examples/perloop/employee01/lib/Employee.pm
package Employee;
use strict;
use warnings;

# use base 'Person';

use parent 'Person';

# our @ISA = ('Person');

1;