package Person;
use strict;

my %default = (NAME=>"Shirley", SEX=>"f", AGE=>26);

# the object constructor
sub new {
        my( $class, %arg ) = @_;
	my $obj      = bless( {}, $class );
	$obj->{NAME} = $arg{NAME} || $default{NAME};
	$obj->{SEX}  = $arg{SEX}  || $default{SEX};
	$obj->{AGE}  = $arg{AGE}  || $default{AGE};
	return $obj;
}

# get/set methods - set the value if given extra arg

sub name {
	my( $self, $value ) = @_;
	$self->{NAME} = $value if defined $value;
	return $self->{NAME};
}

sub sex {
	my( $self, $value ) = @_;
	$self->{SEX} = $value if defined $value;
	return $self->{SEX};
}

sub age {
	my( $self, $value ) = @_;
	$self->{AGE} = $value if defined $value;
	return $self->{AGE};
}

use overload '""' => \&as_string;

# new method
sub as_string {
	my( $self ) = @_;

	my $class = ref($self);
	my $name = $self->name;
	my $age = $self->age;
	my $sex = $self->sex;
	return "$class: name=$name, age=$age, sex=$sex\n";
}

# print reimplemented
sub print {
	my( $self ) = @_;

	print $self;
}

1;
