# The package name will become the class name package Square; use strict; use warnings; # Always a good idea # public Square new(double size) # Instantiate a square of a specified size. sub new { my($package, $size) = @_; die unless scalar @_ == 2; my $this = [ $size # Length of side of the square ]; bless $this, $package or die; return $this; } # private double _GetSize() # Get the side length. This method is private, denoted by the underscore. # This is not enforced, but at least it is clearly indicated. sub _GetSize { my($this) = @_; die unless scalar @_ == 1; return $this->[0]; } # public double Area() # Get the area of the square. sub Area { my($this) = @_; die unless scalar @_ == 1; return $this->_GetSize() * $this->_GetSize(); } 1; # Package needs to return true