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