A More Elaborate Mutator

use DateTime;

sub date_of_birth {
  my $self = shift;

  if(@_) {
    if(shift =~ /^(\d\d\d\d)-(\d\d)-(\d\d)/) {
      $self->{dob} = DateTime->new(
                       year   => $1,
                       month  => $2,
                       day    => $3,
                     );
    }
    else {
      die "invalid date, expected YYYY-MM-DD";
    }
  }

  return $self->{dob};
}