Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Re: RFC Magic::Attach

by shotgunefx (Parson)
on Jan 21, 2003 at 03:52 UTC ( [id://228574]=note: print w/replies, xml ) Need Help??


in reply to Re: RFC Magic::Attach
in thread RFC Magic::Attach

Point taken. I was intending to document it better after the feedback from this post (I assume I'll be making much changes)

"It doesn't help that the ~ magic vtable has nothing to do with the "traditional" meaning of magic -- that is, it's never automaticly called."

Actually if callbacks are setup they are automatically called. The only callback I am installing is for the freeing of the SV so that it won't leak the attached reference.

I do plan on another module to allow user-defined callbacks but I didn't want to get over my head. My grasp of things internal is still less than *COUGH* um, firm.

I added SvREFCNT for some additional tests I am going to implement. I didn't want to require any prerequisites for the tests alone.

Thanks,
-Lee

"To be civilized is to deny one's nature."

Replies are listed 'Best First'.
Re: Re: Re: RFC Magic::Attach
by theorbtwo (Prior) on Jan 21, 2003 at 04:29 UTC

    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).

      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."
        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

        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).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://228574]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (3)
As of 2024-04-19 20:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found