|Perl Monk, Perl Meditation|
RFC Magic::Attachby shotgunefx (Parson)
|on Jan 21, 2003 at 03:11 UTC||Need Help??|
I've created a module Magic::Attach. It allows you to attach one referant to another.
The purpose of which is to allow a sub or any other type of object to attach some private data to a reference. This could be for lazy evaluation of arguments or whatever purpose you can think of.
When you attach a ref to another ref, you can optionally specify a nameid to avoid collisions. Multiple attachments are fine but other modules that implemented their own magic using the '~' user extension type may clobber us if they are less careful.
The module can be found here
This is my first real forray into XS so I'm sure there are things that could be done better. Comments and criticisms welcome.
It works with 5.6.1 and above (possibly with earlier versions but I haven't confirmed this.) The naming of the routines may change. (Would bind/bound/unbind be better suited?)
My other thought is if this is a generally useful module, perhaps the "optional nameid" shouldn't be optional (Currently it defaults to Magic::Attach). I worry that if this finds use and the default nameid are used in two different places it will lead to very, very subtle bugs. I can't speak for anyone else but before embarking on this, I would never think to look at "magic vtables" for problems.
I'd really appreciate any feedback on the implementation, usefulness, etc of this.
"To be civilized is to deny one's nature."
The "magic" refered to is internal to the perl interpreter. See "Magic Variables" in perlguts for more information.
update Jan 21 one more example.