Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

OK, everybody is going to give you different answers, from "you can't do that" to "you shouldn't do that"... I'll try to explain the "why"

Perl has, per se, non concept of "private" methods: a package is a name space: it contains names for things (subroutines, but also variables, etc). OOP in Perl is based on the fact that, by blessing a reference, you attach to it the name of a package. Then, when you use it with the "arrow notation", Perl looks at the name of the package you have attached to the reference, and starts from it to look for a subroutine with the name you specified (I assume you know how the inheritance works). At no point Perl consults some attribute of the reference, the packages, or the subroutines, to discover if it was OK for you to call that subroutine.

This is a design choice. Maybe not the best one (Perl6 will have proper privacy of members), but the one that has been made. The idea was that it was both easier and more flexible to do it this way, and that the programmers would just avoid to step on each other's toes.

There are several modules out there that muck with the inheritance, add methods to other classes, and generally behave pretty poorly if you judge them "by the book". But the main goal, in Perl, is to get the job done. If you need strong encapsulation and privacy, there are modules that can give them to you (you'll get plenty of pointers from other people, I'm feeling a bit lazy at the moment); and the reason that you can get them is that Perl does not provide them itself, but instead leaves everything wide open for anybody to tinker with.

Oh, as a sidenote, Perl6 will both have privacy and encapsulation, and permit to tinker with classes at will. It will just be a little better presented ;-)

        dakkar - Mobilis in mobile

Most of my code is tested...

Perl is strongly typed, it just has very few types (Dan)

In reply to Re: How can I add private data/methods in parent class? by dakkar
in thread How can I add private data/methods in parent class? by pijush

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2022-05-24 14:55 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (84 votes). Check out past polls.