What you're looking for is a way to make perl more like C++ or Java, enforcing some sort of privilege (public, private, protected, package(Java)). Perl doesn't do that. Perl takes a completely different tract.

There is a simple convention in perl: any function with a leading underscore (which would be against The Rules(TM) in C - that is reserved for the compiler vendor) is considered "private." Other packages can call it, but it's not recommended - do so at your own risk.

That said, there are ways to enforce things like this. For example, you could create "sessions", and store the real object data in a private hash, e.g.:

my %data; # private hash sub new { my $data = rand(); my $self = bless \$data; $data{$$self}{BKG_IMAGE} = 'image'; } my $bkg_img = # private anon-sub sub { my $self = shift; if (@_) { $data{$$self}{BKG_IMAGE} = shift; } $data{$$self}{BKG_IMAGE}; } # called as: $self->$bkg_img('new_image') # or $image = $self->$bkg_img();

Not recommended. Just document that _bkg_img is a private internal method. You'd be surprised how often a method you think should be private really shouldn't be ;-)


In reply to Re: Referencing an object's value by Tanktalus
in thread Referencing an object's value by jacques

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.