Debug::LTrace - Perl extension to locally trace subroutine calls


Version 0.01


    use Debug::LTrace;

        my $tracer = Debug::LTrace->new('tsub'); # create local tracer
        tsub(1); # Tracing is on while $tracer is alive
    tsub(2); # Here tracing is off
    sub tsub {shift}


    perl -MDebug::LTrace='*' # trace all subroutines in package main


Debug::LTrace instruments subroutines to provide tracing information upon every call and return. Using Debug::LTrace does not require any changes to your sources. The trace information is output using the standard warn() function.

It was inspired by Debug::Trace, but introduces new features such as

  • Lexically scoped tracing

  • Implements tracing in such way that the standard caller function works correctly

  • Enable package tracing (using '*' syntax)

  • Nice output formatting

  • More debug information (time of execution, call context...)

Also Debug::LTrace supports Debug::Trace syntax (modifiers are not supported yet).

Devel::TraceCalls - Powerful CPAN module but too complex API and not so convenient as Debug::LTrace

Some useful examples:

from command line:
    # Trace "foo" and "bar" subroutines
    perl -MDebug::LTrace=foo,bar 

    # Trace all subroutines in current package ( "main" )
    perl -MDebug::LTrace='*' 
    # Trace all subroutines in package "SomeModule" and "AnotherModule::foo"
    perl -MDebug::LTrace='SomeModule::*, AnotherModule::foo' 
the same in code:
    # Trace "foo", "bar" subroutines in current package (can be not "main")
    use Debug::LTrace qw/foo bar/;  

    # Trace all subroutines in current package (can be not "main")
    use Debug::LTrace qw/*/; 
    # Trace all subroutines in package "SomeModule" and "AnotherModule::foo"
    use Debug::LTrace qw/SomeModule::* AnotherModule::foo/; 
local tracing (is on only when $tracer is alive):
    # Trace foo, bar subroutines in current package (can be not "main")
    my $tracer = Debug::LTrace->new( 'foo',  'bar' );  
    # Trace all subroutines in current package (can be not "main")
    my $tracer = Debug::LTrace->new('*'); 
    # Trace all subroutines in package SomeModule and AnotherModule::foo
    my $tracer = Debug::LTrace->new('SomeModule::*', 'AnotherModule::foo');

Output trace log using custom function

Debug::LTrace outputs trace log using standart warn function. So you can catch SIGWARN with this code:

    $SIG{__WARN__} = sub {
        if ( $_[0] =~ /^TRACE/ ) {
            goto &custum_sub
        } else {
            print STDERR @_;  


Debug::LTrace->new($sub [, $sub2, $sub3 ...] );

$sub can be fully-qualified subroutine name like SomePackage::foo and will enable tracing for subroutine SomePackage::foo

$sub can be short subroutine name like foo willl enable tracing for subroutine foo in current namespace

$sub can be fully-qualified mask like SomePackage::* will enable tracing for all subroutines in SomePackage namespace including improrted ones


  • improve Debug::LTrace compatibility (add modifiers support)

  • enabling tracing for whole tree of modules

  • callback support to handle debug output


"koorchik", <"koorchik at">


Please report any bugs or feature requests to bug-debug-ltrace at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

    perldoc Debug::LTrace

You can also look for information at:


Copyright 2010 "koorchik".

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See for more information.


Debug::Trace, Devel::TraceCalls, Hook::LexWrap, Devel::Symdump