rendered paste bodyuse strict;
use warnings;
use HashObj;
package Goth;
sub Summon {
my ($caller, %argh) = @_;
my $class = ref($caller) || $caller;
my $self = bless {}, $class;
my $argr = bless \%argh, "HashObj";
$self->{name} = $argr->get("name", "Ebony");
$self->{happiness} = $argr->get("happiness", -0.8);
return $self;
}
sub DepressBy {
my ($self, $amount) = @_;
$self->{happiness} -= $amount;
}
sub GetHappiness {
my $self = shift;
return $self->{happiness};
}
sub GetName {
my $self = shift;
return $self->{name};
}
1;
# program start
#my @Goffs = map {Goff(name => $_)} qw( Ebony Drako Dumblydore Vampire );
my @Goffs = (
Goth->Summon(),
Goth->Summon(name => 'Draco', happiness => 0.5),
Goth->Summon(name => 'Dumblydore', happiness => 0.8),
Goth->Summon(name => 'Vampire', happiness => -0.2)
);
map {$_->DepressBy(0.7);} @Goffs;
my @wetList = grep {$_->GetHappiness() < -0.5} @Goffs;
@wetList = map {$_->GetName()} @wetList;
print "@wetList\n";