moose-class-employee.txt

#=============================================================================
package Person;

use Moose;

has surname => (
    is => 'ro',
    isa => 'Str', # attribute need to be a string
    required => 1, # required in constructor
);

has forename => (
    is => 'ro',
    isa => 'Str', # attribute need to be a string
    required => 1, # required in constructor
);

has age => (
    is => 'rw',
    isa => 'Int', # attribute need to be a digit
);

sub name {
    my $self = shift;
    return join ", ", $self->surname, $self->forename;
}

#=============================================================================
package Person::Employee;

use Moose;

extends 'Person';

has workplace => (
    is => 'rw',
    isa => 'Str',
    required => 1,
);

#=============================================================================
package main;

my $workwoman = Person::Employee->new(
                    surname => "Lisa",
                    forename => "Simpson",
                    workplace => "Simpsons",
                    age => 10,
                );

print "!! Working example:\n";
print $workwoman->name, "\n";

print "\n" x 4; # seperate working with error

print "!! Missing parameters to person:\n";
my $workman = Person::Employee->new(surname => "foo", forename => "bar");