The following modification does not assign to a glob. Do this avoid the cache reset issue?
#!/usr/local/bin/perl
use warnings;
use strict;
use Want;
sub lvalueMethod($) {
my ($name) = @_;
my ($package) = caller;
no strict 'refs';
*{$package . "::" . $name} = sub :lvalue {
my $self = shift;
if (!want('LVALUE') && ref($self->{$name}) eq 'CODE') {
goto &{$self->{$name}};
}
$self->{$name};
};
}
{
package Foo;
sub new { bless {}, shift; }
main::lvalueMethod("bar");
}
my ($x) = Foo->new();
print "$x\n";
$x->bar = 5;
print $x->bar, "\n";
$x->bar = sub { print( @_, "\n" ); };
$x->bar("Hello World");
Remember: There's always one more bug.