#!/usr/bin/perl
use strict;
use warnings;


{
  # === A perl object =========================
  package Horse;

  our $count=0;     # A class variable

  # Invoke this with Horse->howMany to see how many horses there are.
  sub howMany {
    my $class = shift;
    return $count;
  }

  # Invoke this with $h = Horse->new to make a new horse.
  sub new {
    my $class = shift;
    $count++;
    my $horse = { color => 'black' };
    bless($horse, $class);
    return $horse;
  }

  # Invoke this with $h->setColor('red')
  sub setColor {
    my $self = shift;
    my ($color) = @_;
    $self->{color} = $color;
  }

  # Invoke this with $h->getColor
  sub getColor {
    my $self = shift;
    return $self->{color};
  }

}

# ====================================================

my $george = Horse->new;
$george->setColor('brown');

my $mary = Horse->new;
$mary->setColor('white');

print "We have " . Horse->howMany . " horses.\n";
for my $horse ($george,$mary){
  print "This horse's color is " . $horse->getColor . ".\n";
}


