John,
I'd like to thank you for asking a good question that has blown my work schedule out of the water and ruined my day ;).
I've wanted the same thing on occasion,(For lazy iterating, etc without tieing blessing, bla,bla) so I did it.
I wrote an XS module using the '~' user defined magic vtable. It respect's other magic and let's specify a name space to avoid collisions. The only problem I have is that I'm trying to set it to use one context sensitive routine for get/set. Once I try and process the argument stack manually it blows up. (Just saying SvOK(target) core dumps.) I'm new to XS and guts so it is probably something stupid I'm doing. The main implementation was quick, but I've been slamming my head off the wall with the optional arugments for like 7 hours. I'll post later today about that problem and then I'll post the module.
When it is it finished it will work like so.
use Magic::Attach;
sub bind {
my ($ref,$shadow) = @_;
attach($ref,$shadow, 'optional namespace');
}
# Later
sub foo {
my $ref = shift;
my $shadow = attach($ref);
$shadow = attach($ref,{}) unless $shadow;
my $count = $shadow->{Someattribute};
}
-Lee
"To be civilized is to deny one's nature."
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.