in reply to why "Bless" in OO Perl
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
|
|---|