Cool. All sounds good, though I wouldn't call it Magic::Attach, then... try Magic::ArbitraryData, perhaps? Magic::Attach::Anything? Magic::Tilde? Anyway, I'd save Magic::Attach for the other module, the one that attaches more traditional types of magic to a var.
Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).
| [reply] |
Perhaps Magic::Bind?
As far as attaching other types of magic , I don't know if that's a good thing. From how I read it, outside of '~' and 'U', none of the other types of magic are supposed to be used outside of the core, though anyone feel free to correct me.
mg_type MGVTBL Type of magic
------- ------ ----------------------------
\0 vtbl_sv Special scalar variable
A vtbl_amagic %OVERLOAD hash
a vtbl_amagicelem %OVERLOAD hash element
c (none) Holds overload table (AMT) on stash
B vtbl_bm Boyer-Moore (fast string search)
D vtbl_regdata Regex match position data (@+ and @-
+vars)
d vtbl_regdatum Regex match position data element
E vtbl_env %ENV hash
e vtbl_envelem %ENV hash element
f vtbl_fm Formline ('compiled' format)
g vtbl_mglob m//g target / study()ed string
I vtbl_isa @ISA array
i vtbl_isaelem @ISA array element
k vtbl_nkeys scalar(keys()) lvalue
L (none) Debugger %_<filename
l vtbl_dbline Debugger %_<filename element
o vtbl_collxfrm Locale transformation
P vtbl_pack Tied array or hash
p vtbl_packelem Tied array or hash element
q vtbl_packelem Tied scalar or handle
S vtbl_sig %SIG hash
s vtbl_sigelem %SIG hash element
t vtbl_taint Taintedness
U vtbl_uvar Available for use by extensions
v vtbl_vec vec() lvalue
x vtbl_substr substr() lvalue
y vtbl_defelem Shadow "foreach" iterator variable /
smart parameter vivification
* vtbl_glob GV (typeglob)
# vtbl_arylen Array length ($#ary)
. vtbl_pos pos() lvalue
~ (none) Available for use by extensions
-Lee
"To be civilized is to deny one's nature." | [reply] [d/l] |
I agree it's too limited to be called Magic::Attach. That would be a good name for a helper module used to implement such a thing, something you wish you had instead of having to write in XS.
The use of the ~ table is meerly an implementation detail. What the module does is attach named attributes to a value at run time. It should be named for its public interface and purpose, not for its implementation details. (Save that name for a concrete implementation when the same interface is implemented multiple ways based on the situation).
This concept is what Perl 6 calls "Properties", and LISP also calls it properties. It's different from the existing Perl attributes or attribs.
—John
| [reply] |
Hm. The on the one hand, yes, from this table. On the other hand, it feels like it should be possible to make a half-tied variable, which invokes a perl sub when stored into, but has no overhead (and does nothing special) when gotten from (or vice-versa). The docs confuse me.
Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).
| [reply] |