package Base; use strict; use warnings; our @ISA = qw(); sub new { my $this = shift; my $class = ref($this) || $this; my $self = {}; bless $self, $class; $self->init(@_); return $self; } # default init, does nothing... sub init {1;} # get/set a scalar member variable sub _gss { @_ > 2 ? $_[0]->{$_[1]} = $_[2] : $_[0]->{$_[1]}; } sub throw { my $self = shift; my($p,$f,$l) = caller(); die "Exception at: ",$p,"->$f($l)\n ",join('',@_); } 1; ######################################## package MyObject; use strict; use warnings; our @ISA = qw(Base); sub init { my($self) = @_; $self->someSetting('default value'); return 1; } sub someSetting {shift->_gss('_myObject__someSetting',@_);} sub someAction { my($self) = @_; print "setting: ", $self->someSetting(), "\n"; } 1; ######################################## package main; use strict; use warnings; my $obj = MyObject->new(); $obj->someAction(); $obj->someSetting('new setting'); $obj->someAction(); exit 0;