Just another Perl shrine | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
I'm working on a module named Data::Alias to provide a comprehensive set of aliasing operations. For those who don't know, aliasing is getting two expressions to identify exactly the same thing. So while setting $x to $y will make $x and $y the same, aliasing $x to $y will make \$x and \$y the same (Diagram). Its interface is simple: alias LIST or alias BLOCK. The function itself is essentially a no-op, but the entire argument list is evaluated with altered semantics where aliasing occurs wheever copying would normally be done. This is achieved by diddling the optree, not by using a source filter. This means you can use natural perl syntax to do all sorts of aliasing:
Currently it supports aliasing assignment to variables, array/hash elements, dereferencing, and globs, including conditional assignment (&&=, ||=). Also push, unshift, splice, and anonymous array/hash constructors. do-blocks return aliases (in fact, they are lvalues). Finally you can return aliases from sub or eval, either implicitly by placing the sub/eval inside alias, or explicitly by using alias return LIST; UPDATE: Putting a conditional expr ( ? :) on the left-side of assignment didn't work. I've added support for it and uploaded a new snapshot. So the big question is... have I overlooked anything? Are there more operations that deserve to receive aliasing semantics inside alias? A minor second issue what to do with aliasing elements of tied arrays and hashes. Currently I just give an error, but I considered checking for special methods like ALIAS_STORE, ALIAS_PUSH, etc. Would this be of any utility at all? And any other sort of feedback is welcome too of course :-) In reply to RFC: Is there more to alias? by xmath
|
|