Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

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

I've researched this a little bit, and I'm not sure that we can work around it. Two things seem to be keeping us from properly inheriting from Bit::Vector:

  1. It doesn't look like you can bless a scalar constant (one marked internally as read-only):

    perl -e '$a = \"constant"; bless($a, "Test");' Modification of a read-only value attempted at -e line 1.

    This is probably normal behavior of Perl (even though I don't understand why), but the problem is that it looks as though Bit::Vector is claiming that its referent is read-only, presumably to prevent you from accidentally modifying its value:

    perl -MBit::Vector -e '$a = new Bit::Vector(8); ${$a} = 2;' Modification of a read-only value attempted at -e line 1.

    This keeps us from re-blessing it into our own class.

  2. The other problem is that Bit::Vector's "new" function is ignoring the first argument to "new", which means it doesn't allow itself to be called in an inherited style. Here's the code in Vector.xs that actually does the blessing:

    reference = sv_bless(sv_2mortal(newRV(handle)), BitVector_Stash);

    This forces the new object to be created in Bit::Vector, ignoring the class passed to the function (it's there in the code, just being ignored).

    I'm no XS expert by any stretch, but this change to Bit::Vector *might* work, which effectively does a stash lookup based on the first argument already passed into the function:

    reference = sv_bless(sv_2mortal(newRV(handle)), gv_stashpv(SvPV_nolen( +class), 1));

    It makes some bad assumptions, though. I'd rather leave this up to the experts to fix properly, if a fix is even desired.

    (update: the above change breaks some of the tests for Bit::Vector, notably the use of $new = $old->new($bits) syntax to create a new Bit::Vector, but your test script does run as you expect.)

The author of the module is Steffen Beyer <mailto:sb@engelschall.com>. I might shoot him an e-mail to ask him if these behaviors and side-effects are intentional.


In reply to Re: How can I inherit from Bit::Vector? by Fastolfe
in thread How can I inherit from Bit::Vector? by toma

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 wandering the Monastery: (4)
As of 2024-04-25 12:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found