use strict;
use warnings;
{
package MyScalar;
use Carp;
sub TIESCALAR {
my $pkg = shift;
carp "TIESCALAR('$pkg')";
bless \do { my $scalar }, $pkg;
}
sub FETCH($) {
my $this = shift;
carp "FETCH($this)";
return $$this;
}
sub STORE($$) {
my ( $this, $value ) = @_;
carp "STORE($this, $value)";
$$this = $value;
}
sub DESTROY {
my $this = shift;
carp "DESTROY($this)";
}
}
{
tie my $scalar, 'MyScalar';
$scalar = 1;
print $scalar, "\n";
$scalar++;
print $scalar, "\n";
print 'tied($scalar) = ', tied($scalar), "\n";
tied($scalar)->STORE(3);
print $scalar, "\n";
}