If tracking multiple tied variables, try something like this instead:use strict; use warnings; { package Debug::Tie::StdScalar; use Tie::Scalar; use Carp; sub AUTOLOAD { our $AUTOLOAD =~ s/Debug:://; carp join " >|< ", "calling $AUTOLOAD", @_[1..$#_], ""; goto &$AUTOLOAD; } } # example use my $x; tie $x, 'Debug::Tie::StdScalar', 4; print $x; $x = 3; $x .= "abc"; ++$x;
Replace Scalar and SCALAR with hash or array to watch aggregates.use strict; use warnings; { package Debug::Tie::StdScalar; use Tie::Scalar; use Carp; sub TIESCALAR { my $obj = &Tie::StdScalar::TIESCALAR(@_); carp join(" >|< ", "calling Tie::StdScalar::TIESCALAR", @_[1..$# +_]), "\n=> ", 0+$obj; $obj; } sub AUTOLOAD { our $AUTOLOAD =~ s/Debug:://; carp join " >|< ", "calling $AUTOLOAD", 0+$_[0], @_[1..$#_], ""; goto &$AUTOLOAD; } }
Update: An obvious enhancement is to catch and show what FETCH returns; up to now I haven't needed to do so, so it is left as an exercise for the reader.
In reply to Debugging with tied variables by ysth
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |