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 other way for do some magic.
package DB;
my %call_info;
@call_info{qw(pack file line sub has_args wantarray evaltext is_require)} = caller($i);
return unless (defined $call_info{pack});
if ($call_info{has_args}) {
# This is only filled, when you call "caller($i)" IN the package 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);
####
Args: CGI=HASH(0x8148d48) > parameter test = this_is_my_text
Args: 1
####
$DB::trace
@DB::dbline
%DB::dbline
@DB::ret
$DB::ret
%DB::sub