Here's another datapoint. Let's have a look at what a blessed object looks like, compared to an ordinary one.

% perl -MDevel::Peek -e 'Dump({}), Dump(bless({}, "Pkg")); ' SV = RV(0x807d01c) at 0x8057b38 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x805716c SV = PVHV(0x805c720) at 0x805716c REFCNT = 2 FLAGS = (SHAREKEYS) IV = 0 NV = 0 [... needless detail omitted ...] SV = RV(0x807d01c) at 0x80572d4 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x805716c SV = PVHV(0x805c720) at 0x805716c REFCNT = 2 FLAGS = (OBJECT,SHAREKEYS) IV = 0 NV = 0 STASH = 0x8057238 "Pkg" [... needless detail omitted ...]

Both are scalars, the first holds a reference to an anonymous hash, the other holds a reference of an anonymous hash that has been blessed (or attached) to a package.

See how the SV (scalar value) structure has an extra bit flipped in its FLAG field that indicates it is an object, and also how the name of the class is recorded too.

Armed with this information, the interpreter then can take a method call on the scalar, and go and find out what code to run from where.

• another intruder with the mooring in the heart of the Perl


In reply to Re: why "Bless" in OO Perl by grinder
in thread why "Bless" in OO Perl by Anonymous Monk

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.