http://qs321.pair.com?node_id=966337

whatnext156 has asked for the wisdom of the Perl Monks concerning the following question:

Ok so I'm just tinkering with OO for the first time, and am bound to have got this totally wrong... BUT... the documentation I can find online on OO seems thin and confusing (where is the idiots guide??). I am struggling with the following and hope someone can enlighten me:

E.g. suppose I want to inherit from Email::Simple and create my own email type. Then I can add my own methods.

package FunnyEmail; use base Email::Simple; sub new{ my $class = shift; my $text = shift; # assume this gets passed my $self=Email::Simple->new($text); $self->{'JOKE'} = undef; # add my own variable bless $self,$class; return $self; }

(Have I even got this right?)

So now I can add methods which monkey about with $self->{'JOKE'}.

But my question is this: if $self refers to the hash created by Email::Simple when Email::Simple->new() was called then isn't there a danger $self->{'JOKE'} is already in use? How do I know I'm not messing up variables used in Email::Simple methods? Do I need browse the Email::Simple code to check the variable I am going to use is available, or am I protected somehow, or some other answer (possibly based on me having got the whole thing wrong from the outset!) ?

Thanks in advance for your help!