More Code 

sub format {
  my($self, $text) = @_;

  $text =~ s/\A\s+//;
  $text =~ s/\s+\Z//;

  my @words = split /\s+/, $text;
  return join ' ', @words;
}