I've to find out, how I can read all lexical variables (declared with "my") in a block of the callerstack. I've found out, that Carp::Heavy uses some of the "magic" things in package DB like the following, to access to the given parameters:
use strict;
use CGI;
my $c = new CGI;
$c->param('test', 'this_is_my_text');
sub one {
my $this_i_want_to_access = 'no_way';
return two($c)
}
sub two {
my $i = 0;
for(1..4) { resolve_caller($_) }
}
sub resolve_caller {
my $i = shift;
# Ups! Inline usage of a package. Not my style, but there is no ot
+her way for do some magic.
package DB;
my %call_info;
@call_info{qw(pack file line sub has_args wantarray evaltext is_re
+quire)} = caller($i);
return unless (defined $call_info{pack});
if ($call_info{has_args}) {
# This is only filled, when you call "caller($i)" IN the packa
+ge DB!!! Otherwise it's empty. It's magic?
my @args = @DB::args;
print "Args: @args";
foreach my $c (@args) {
if(ref($c)) {
print " > parameter test = " . $c->param('test');
}
}
print "\n";
return;
}
return;
}
print one(1);
Have a look at the two comments. There is some magic in this code. I can use it, but I don't understand. This prints out:
Args: CGI=HASH(0x8148d48) > parameter test = this_is_my_text
Args: 1
So at this way, I can access to lexical variables given into subroutines in callerstack. But I want to look around in the subroutines and, for example, want to access to $this_i_want_to_access.
There are some special variables, that sounds good, but what magical things I've to do, to fill them? How can I find some documentation about this?
$DB::trace
@DB::dbline
%DB::dbline
@DB::ret
$DB::ret
%DB::sub