All pastes #2051085 Raw Edit

ebony-oop

public text v1 · immutable
#2051085 ·published 2011-04-27 04:18 UTC
rendered paste body
use strict;
use warnings;

=head 1
sub slit {
    my ($writDensity) = @_;

    return $_/12;
}

my @writs = qw( 12 54 72 2 6 12 );

print "@writs\n";
my @blood = map &slit, @writs;
print "@blood\n";

=cut

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";