#!/usr/bin/perl use warnings; use strict; use constant TRUE => 1; use constant FALSE => 0; use FindBin qw($Bin); { package user::name; sub new { my $class = shift; my $name = shift; bless \$name, $class; } sub get { my $self = shift; return $$self; } sub set { my $self = shift; $$self = shift; } } { package user::password; sub new { my $class = shift; my $password = shift; bless \$password, $class; } sub get { my $self = shift; return $$self; } sub set { my $self = shift; $$self = shift; } } { package user; sub new { my $self = bless {}, shift; my %options = @_; $self->{name} = user::name->new ( $options{name} ); $self->{password} = user::password->new( $options{password} ); return $self; } sub name { my $self = shift; $self->{name}; } sub password { my $self = shift; $self->{password}; } } my $paul = user->new( name => 'paul', password => 'passwd' , ); my $anne = user->new( name => 'anne', password => 'nopwd', ); print $paul->name->get, "\n", $paul->password->get, "\n"; print "\n"; print $anne->name->get, "\n", $anne->password->get, "\n";