in reply to Re: Perl OO best practice?
in thread Perl OO best practice?

Thanks chromatic and repellent! You both hit upon the same concern: violating encapsulation.

I was most concerned about the odd syntax in the Orange::serve() method:

31 sub serve { 32 my $self = shift; 33 return ( $self->{apple} ) ? $self->{apple}->serve() : 'squeeze +d'; 34 } 35

At first read, $self->{apple} looks like a hash ref, but then we are calling a method from it with the ->serve(). I have not come across that syntax, but it works.

Your suggestions will help as I clean up this code.
Thanks!
sjs

Replies are listed 'Best First'.
Re^3: Perl OO best practice?
by repellent (Priest) on Feb 10, 2010 at 01:14 UTC
    • $self->{apple} is not a hashref. It returns the first object shifted in at: $self{apple} = shift;  ## other objects (hopefully)
    • $self is a blessed hashref.
    • $self->{apple}->serve() calls ->serve on the object returned by $self->{apple}