Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Thou Shall Not Covet thy Object's Internals

by princepawn (Parson)
on Apr 26, 2001 at 01:31 UTC ( [id://75625]=note: print w/replies, xml ) Need Help??


in reply to Thou Shall Not Covet thy Object's Internals

I was asked to expand on my comments about ties as being good ways of hiding an object's implementation. I will use Tie::Cycle.

here is a normal usage of this module:

use Tie::Cycle; tie my $cycle, 'Tie::Cycle', [ qw( FFFFFF 000000 FFFF00 ) ]; print $cycle; # FFFFFF print $cycle; # 000000 print $cycle; # FFFF00 print $cycle; # FFFFFF back to the beginning

From the standpoint of a person who is used to getting at object internals, he has no hope here. In fact, higher management could install the Tie::Cycle module, and the programmers would be free to use the module, making use of normal Perl syntax but with Tie::Cycle semantics.

But in no case could they use their tied scalar to access their "object" in this case, $cycle.

It's funny that I wrote this post, because I used to hate Perl ties. My way of describing them was:

They take a perfectly obvious piece of Perl code and make it so you have no idea what it might do anymore.

But after reading Ovid's post, I guess I have to say

They take a Perl module whose privates might have been violated using OOP availability and allow Perl to do the FETCHing and STOREing for the programmer, with a large variety of available semantics.

Replies are listed 'Best First'.
(tye)Re: Thou Shall Not Covet thy Object's Internals
by tye (Sage) on Apr 26, 2001 at 02:33 UTC

    To truely protect your object internals, you need to use closures.

    Update: Note that I find doing such to be not only overkill but a bad idea in Perl (except perhaps within large Perl projects where the temptation to peek at another class's implementation, your motivation to protect other team members from themselves, and the interdependence of classes may all be higher). And with new modules for getting at lexicals other than your own, the extra 'protection' provided now isn't much anyway.

            - tye (but my friends call me "Tye")
Re: Re: Thou Shall Not Covet thy Object's Internals
by merlyn (Sage) on Apr 26, 2001 at 01:55 UTC
    But in no case could they use their tied scalar to access their "object" in this case, $cycle.
    Wrong. See perldoc -f tied.

    -- Randal L. Schwartz, Perl hacker

Re: Re: Thou Shall Not Covet thy Object's Internals
by hdp (Beadle) on Apr 26, 2001 at 01:57 UTC
    You seem to be forgetting tied.

    hdp.

Re^2: Thou Shall Not Covet thy Object's Internals
by brian_d_foy (Abbot) on Jan 16, 2006 at 04:19 UTC

    You forgot the next line in the synopsis for Tie::Cycle, which shows you how to get to the underlying object. I supplied other methods besides those for the tie interface.

    (tied $cycle)->reset; # back to the beginning

    Farther down in the docs I list a couple other object methods you can use.

    --
    brian d foy <brian@stonehenge.com>
    Subscribe to The Perl Review

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-09-18 19:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (25 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.