Can I tie a variable multiple times? I'd try it myself, but I'm not sure of the syntax. I want to tie a hash to Cache::Memcached::Tie and IPC::Shareable.
No. Confirming bvr's guess, a variable can only have a single "tied" magic. When you call tie
on an already-tied variable, the existing tie-magic (and the associated tied object) is discarded before the new tie is created.
Toy example:
package Foo;
sub TIESCALAR { return bless [] }
sub DESTROY { print "Destroying Foo\n" }
package Bar;
sub TIESCALAR { return bless [] }
sub DESTROY { print "Destroying Bar\n" }
package main;
tie my $var, "Foo";
print "Tied to ", ref tied $var, "\n";
tie $var, "Bar";
print "Tied to ", ref tied $var, "\n";
Output:
Tied to Foo
Destroying Foo
Tied to Bar
Destroying Bar
Not only is this not possible, but it's not sensible either. What is a fetch supposed to mean in this context? How to deal with them returning two different values?
What I suspect you want is a multilevel caching system, you may want to look into CHI for that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With