The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Devel::EdTrace - Print out each line before it is executed (like sh -x)

SYNOPSIS

  perl -d:Trace program

DESCRIPTION

If you run your program with perl -d:Trace program, this module will print a message to standard error just before each line is executed. For example, if your program looks like this:

        #!/usr/bin/perl
        
        
        print "Statement 1 at line 4\n";
        print "Statement 2 at line 5\n";
        print "Call to sub x returns ", &x(), " at line 6.\n";
        
        exit 0;
        
        
        sub x {
          print "In sub x at line 12.\n";
          return 13;
        }

Then the Trace output will look like this:

        >> ./test:4: print "Statement 1 at line 4\n";
        >> ./test:5: print "Statement 2 at line 5\n";
        >> ./test:6: print "Call to sub x returns ", &x(), " at line 6.\n";
        >> ./test:12:   print "In sub x at line 12.\n";
        >> ./test:13:   return 13;
        >> ./test:8: exit 0;

This is something like the shell's -x option.

DETAILS

Inside your program, you can enable and disable tracing by doing

    $Devel::EdTrace::TRACE = 1;   # Enable
    $Devel::EdTrace::TRACE = 0;   # Disable

or

    Devel::EdTrace::trace('on');  # Enable
    Devel::EdTrace::trace('off'); # Disable

Devel::EdTrace exports the trace function if you ask it to:

import Devel::EdTrace 'trace';

Then if you want you just say

    trace 'on';                 # Enable
    trace 'off';                # Disable

New features:

$Devel::EdTrace::PrintEval (or environmental variable TRACEEVAL) - Sets whether or not you want to have 'constant eval set on' This evaluates and shows the value of the variables evaluated on a left panel of the scrren. For example:

        >> for ($xx = 0; $xx < 10; $xx++)             | for ( = 0; < 10; ++)
        >> {                                          | {
        >>     $yy = $xx;                             |    = 0
        >> }                                          | }

Note that the eval happens before the statement, not after.

$Devel::EdTrace::PrintLevel (or environmental variable TRACELEVEL)

    - sets whether or not indent is going to be turned on. 

          If set to one, no indent is done. 

          If set to 2, all output will be indented to the level 
          at which the code was called (ie: the number of frames in)

$Devel::EdTrace::ExpandBuiltin (or environmental variable TRACEBUILTIN)

    - when set to 1 - and in conjunction with PrintEval, makes the functions 
          keys, values and map be evaluated in place when evaluated

        - when set to a pipe (|) separated list, evaluates all functions in the list 
          (eg: $ENV{TRACEBUILTIN} = 'keys|values' will evaluate keys and values functions)
        

$Devel::EdTrace::TraceSys (or environmental variable TRACESYS)

        - Causes each statement in the code to be followed by a system call (the one
          in TRACESYS). For example

          $ENV{TRACESYS} = 'ls'

          will do an 'ls' before each perl statement.

Environmental variable TRACELOG

        Puts all tracing to a log (named tracelog).

Envionmental variable TRACERM

        In conjunction with TRACELOG, removes any previous tracelog before writing to the new tracelog.

Author