Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a call stack listing in Perl?

Is there a way I can access (for printout) a list of sub + module to arbitrary depth of sub-calls preceding a current position in a Perl script?

I need to make changes to some Perl modules (.pm's). The workflow is initiated from a web-page thru a cgi-script, passing input through several modules/objects ending in the module where I need to use the data. Somewhere along the line the data got changed and I need to find out where.

like image 802
slashmais Avatar asked Oct 23 '08 08:10

slashmais


People also ask

What is call stack stack trace?

a call stack is a stack data structure that stores information about the active subroutines of a computer program. A stack trace is a report of the active stack frames at a certain point in time during the execution of a program.

What is carp in Perl?

The carp function in Perl is the basic equivalent of warn and prints the message to STDERR without actually exiting the script and printing the script name.

What is caller in Perl?

In a list context, with no arguments specified, caller returns the package name, file name and line within the file for the caller of the current subroutine. If EXPR is specified, caller returns extended information for the caller EXPR steps up.


1 Answers

You can use Devel::StackTrace.

use Devel::StackTrace; my $trace = Devel::StackTrace->new; print $trace->as_string; # like carp 

It behaves like Carp's trace, but you can get more control over the frames.

The one problem is that references are stringified and if a referenced value changes, you won't see it. However, you could whip up some stuff with PadWalker to print out the full data (it would be huge, though).

like image 197
Ovid Avatar answered Oct 04 '22 20:10

Ovid