# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# Person.pm
#
# This module describes a Person object
#
# Author: John Berry
# Date: 12/11/03
#
# Version 0.01
# 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 

package Person;

# name: new
# description: creates a new person object
# usage: my $new_person = Person->new();
# note: you may optionally pass a name and age parameter at the time the
#       new person object is created, such as:
#         my $other_new_person = Person->new('Ed', 45);
sub new {
  my $class = shift;
  my $person = {
                name => '',
                age => 0,
                brothers => [],
                sisters => [] 
               };

  $person->{name} = shift if @_;
  $person->{age} = shift if @_;

  bless($person, $class);

  return $person;
}

# name: set_name
# description: sets the name of a person object
# usage: $person_obj->set_name($name);
# note:
sub set_name {
  my $self = shift;
  $self->{name} = shift;
}


# name: get_name 
# description: returns the name of a person object
# usage: $person_obj->get_name();
# note: 
sub get_name {
  my $self = shift;
  return $self->{name};
}

 
# name: set_age
# description: sets the age of a person object 
# usage: $person_obj->set_age($age); 
# note:  
sub set_age {
  my $self = shift;
  $self->{age} = shift;
}
 
# name: get_age 
# description: returns the age of a person object
# usage: $person_obj->get_age();
# note:  
sub get_age {
  my $self = shift;
  return $self->{age};
}

 
# name: add_brother 
# description: adds a brother to a person object 
# usage: $person_obj->add_brother($brother); 
# note:  
sub add_brother {
  my $self = shift;
  push(@{$self->{brothers}}, shift);
}
 
# name: print_brothers 
# description: prints a list of brothers in a person object
# usage: $person_obj->print_brothers(); 
# note: 
sub print_brothers {
  my $self = shift;

  print("Brothers are ");
  foreach my $brother (@{$self->{brothers}}) {
    if($brother ne $self->{brothers}[(scalar(@{$self->{brothers}}) - 1)]) {
      print("$brother, ");
    } else {
      print("$brother.\n");
    }
  }
}


# name: add_sister 
# description: adds a sister to a person object 
# usage: $person_obj->add_sister($sister); 
# note:  
sub add_sister {
  my $self = shift;
  push(@{$self->{sisters}}, shift);
}

 
# name: print_sisters 
# description: prints a list of sisters in a person object
# usage: $person_obj->print_sisters(); 
# note: 
sub print_sisters {
  my $self = shift;

  print("Sisters are ");
  foreach my $sister (@{$self->{sisters}}) {
    if($sister ne $self->{sisters}[(scalar(@{$self->{sisters}}) - 1)]) {
      print("$sister, ");
    } else {
      print("$sister.\n");
    }
  }
}


# name: summarize 
# description: creates a summary of a person object
# usage: $person_obj->summarize(); 
# note:  
sub summarize {
  my $self = shift;

  print(
        "The person '", 
        $self->get_name(), 
        "' is ", 
        $self->get_age(), 
        " years old.\n"
       );

  $self->print_brothers();
  $self->print_sisters();

  print("\n\n");
}

1;
