1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#!/usr/bin/perl -w
#****c* Box/SquareBox
# FUNCTION
# A box with the property that are sides are equal.
# ATTRIBUTES
# SIDE_LENGTH -- the length of each side
# DERIVED FROM
# Box
# SOURCE
package SquareBox;
use Box;
use vars ('@ISA');
@ISA = ("Box");
sub new {
my $classname = shift;
my $self = $classname->SUPER::new(@_);
$self->{SIDE} = 1;
return $self;
}
#*******
#****m* Box/SquareBox::side
# FUNCTION
# Set or get the side length of the square box.
# SYNOPSIS
# $boxref->side(100.25);
# my $length = $boxref->side();
# RETURN VALUE
# The volume of the box
# SOURCE
sub side {
my $self = shift;
if (@_) {
my $length = shift;
$self->{SIDE} = $length;
}
return $self->{SIDE};
}
#*******
#****m* Box/SquareBox::volume
# FUNCTION
# Compute the volume of a square box.
# SYNOPSIS
# my $volume = $boxref->volume();
# RETURN VALUE
# The volume of the box
# SOURCE
sub volume {
my $self = { };
return $self{SIDE} * $self{SIDE} * $self{SIDE} ;
}
#*****
1;
|