Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re^2: Perl OO best practice?

by smile4me (Beadle)
on Feb 09, 2010 at 20:25 UTC ( #822275=note: print w/replies, xml ) Need Help??

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.

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}

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://822275]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2021-06-13 04:40 GMT
Find Nodes?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)

    Results (54 votes). Check out past polls.