What happens when you try it?
package Tie::Scalar::Yell; sub TIESCALAR { bless \my $x, shift } sub STORE { ${ $_[0] } = $_[1] } sub FETCH { warn "accessed\n"; return ${ $_[0] }; } package main; tie my $x, 'Tie::Scalar::Yell'; $x = 'yeller'; print "yeller: $x\n"; # accessed here copier( $x ); sub copier { my $arg = shift; # accessed here print "my arg once: $arg\n"; # ...or here print "my arg twice: $arg\n"; # here? } __END__ accessed yeller: yeller accessed my arg once: yeller my arg twice: yeller
The magic goes away. I didn't know that for sure when I posted, but I suspected that would be the case. That's why I also mentioned using overload.
package Overload::Yell; use overload '""' => sub { warn "string\n"; return 'foo' }, '0+' => sub { warn "number\n"; return 123 }, ; sub new { bless {} } package main; my $x = Overload::Yell->new(); print "yeller: $x\n"; # accessed here copier( $x ); sub copier { my $arg = shift; # accessed here print "my arg once: $arg\n"; # ...or here print "my arg twice: $arg\n"; # here? } __END__ string yeller: foo string my arg once: foo string my arg twice: foo
That works fine except for having to overload '=' too.
Either way, I think it's altogether too much hassle to test a cache so simple.
In reply to Re^3: How to test caching?
by kyle
in thread How to test caching?
by JavaFan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |