Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I'm using the fields and base pragmata in 5.8.0 for some OO stuff I'm working on. I find the combination pretty elegant, and appreciate them very much.

However, I've encountered a small problem (that vexed me quite a bit until I figured out where the issue was). Specifically, if all of the fields in a super-class are private (i.e., their names start with underscores), then sub-classes fail to respect them when inheriting. The result is that new fields in the sub-class write themselves into the same pseudo-hash slots as the fields of the super class. If there is even one non-private field in the super-class, then the sub-class fields make room for all of the super-class fields (even the private ones).

To be more specific, if the superclass Foo starts like this:

package Foo; use strict; use fields qw(_foo); ...
and a subclass Bar looks like this:
package Bar; use strict; use base 'Foo'; use fields qw(_bar _baz); ...
Then if you set the _bar field for a Bar instance, it clobbers whatever was in the _foo field. But if Foo was defined as this instead:
package Foo; use strict; use fields qw(unused _foo); ...
Then Bar respects Foo's fields (even the private ones).

I've put up a page with a script demonstrating the problem, and another script with the trivial fix. Output of each script is at the bottom, after __END__. You can also see the output of perl -V.

Is this a known problem? Is there a patch already available? If not, to whose attention should I bring it? It's not a big deal to work around ("unused" field, anyone?), but it seems to me that base.pm and fields.pm probably be fixed.


In reply to Bug in 5.8.0 fields/base pragmata? by talkasab

Title:
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 How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-25 18:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found