If it is, I need some way to know whether my referent is blessed. However, "sv_isobject" works on a reference. Is there any similar thing works on a referent?

You'll kind of have to clarify what you mean here by "reference" and "referent".

Warning: Blessing involves magic, and I get very antsy around anything to do with (XS) magic.

When you "bless a reference", the magic is attached to the thing referenced, not the reference itself, despite that you need a reference to perform the blessing.

My evidence for this:

#! perl -slw use strict; my( $scalar, @array, %hash ); print for \( $scalar, @array, %hash ); =comment Prints SCALAR(0x2a7c20) ARRAY(0x2a7c80) HASH(0x2a7d28) =cut bless $_, 'fred' for \( $scalar, @array, %hash ); print for \( $scalar, @array, %hash ); =comment Prints fred=SCALAR(0x2a7c20) fred=ARRAY(0x2a7c80) fred=HASH(0x2a7d28) =cut my $newref = \$scalar; print $newref; =comment Prints fred=SCALAR(0x2a7c20) =cut my $ref2ref = \\$scalar; print $ref2ref; print $$ref2ref; =comment Prints REF(0x6e148) fred=SCALAR(0x2a7c20) =cut

Notice how $newRef, and the referent of $ref2ref know that it is the thing they are pointed at that is blessed.

Take that one step further and assign a reference to a new, unblessed thing to a previously blessed reference, and it now knows it refers to a unblessed thing:

$newref = \ 'fred'; print $newref;; =comment Prints SCALAR(0x2c7d70) =cut

So, the common speech pattern of "a blessed reference" is really a misnomer. What we actually have is "a reference to a blessed thing".

Turning this back to your statement above, sv_isobject() is defined as:

Returns a boolean indicating whether the SV is an RV pointing to a blessed object. If the SV is not an RV, or if the object is not blessed, then this will return false.

Only the referent is blessed, but you have to pass an RV that references it to test whether it is blessed or not.

(Doesn't make a whole bunch of sense to me, but I told you I get antsy around magic. :)

And finally:

Is it harmful if I bless a blessed object?

Re-blessing an object just replaces the package it is blessed into with the new package (or the same). But the old blessing is forgotten. Whether this is a mistake depends upon what you are trying to achieve.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^5: SV creation inside XS by BrowserUk
in thread SV creation inside XS by llancet

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.