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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Debugging with tied variables
by rob_au (Abbot) on Dec 08, 2003 at 02:26 UTC | |
by ysth (Canon) on Dec 08, 2003 at 02:43 UTC | |
|
Re: Debugging with tied variables
by davido (Cardinal) on Dec 08, 2003 at 16:58 UTC | |
by ysth (Canon) on Dec 08, 2003 at 18:01 UTC |