package Attack {
use Moo;
use Types::Standard qw( Str Int );
has type => ( is => 'ro', isa => Str );
has damage => ( is => 'ro', isa => Int );
has speed => ( is => 'ro', isa => Int );
}
####
sub light {
my $self = shift;
return $self->new(
type => 'light',
damage => '1',
speed => '5',
);
}
sub fast {
my $self = shift;
return $self->new(
type => 'light',
damage => '1',
speed => '7',
);
}
sub heavy {
my $self = shift;
return $self->new(
type => 'heavy',
damage => '2',
speed => '4',
);
}
####
sub BUILDARGS {
my ($self, @args) = @_;
if ($args[0] eq 'heavy') {
return {
type => 'heavy',
damage => '2',
speed => '4',
};
}
# same for 'light' and 'fast' of course
else {
return { @args };
}
}
####
my $att1 = Attack->heavy;
####
my $att2 = Attack->new('heavy');