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} #or perl -MDebug::LTrace='*' yourprogram.pl # 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
caller
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
# Trace "foo" and "bar" subroutines perl -MDebug::LTrace=foo,bar yourprogram.pl # Trace all subroutines in current package ( "main" ) perl -MDebug::LTrace='*' yourprogram.pl # Trace all subroutines in package "SomeModule" and "AnotherModule::foo" perl -MDebug::LTrace='SomeModule::*, AnotherModule::foo' yourprogram.pl
# 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/;
# 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');
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 @_; } }
$sub can be fully-qualified subroutine name like SomePackage::foo and will enable tracing for subroutine SomePackage::foo
SomePackage::foo
$sub can be short subroutine name like foo willl enable tracing for subroutine foo in current namespace
foo
$sub can be fully-qualified mask like SomePackage::* will enable tracing for all subroutines in SomePackage namespace including improrted ones
SomePackage::*
SomePackage
improve Debug::LTrace compatibility (add modifiers support)
enabling tracing for whole tree of modules
callback support to handle debug output
"koorchik", <"koorchik at cpan.org">
<"koorchik at cpan.org">
Please report any bugs or feature requests to bug-debug-ltrace at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Debug-LTrace. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-debug-ltrace at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Debug::LTrace
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Debug-LTrace
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Debug-LTrace
CPAN Ratings
http://cpanratings.perl.org/d/Debug-LTrace
Search CPAN
http://search.cpan.org/dist/Debug-LTrace/
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 http://dev.perl.org/licenses/ for more information.
Debug::Trace, Devel::TraceCalls, Hook::LexWrap, Devel::Symdump
To install Debug::LTrace, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Debug::LTrace
CPAN shell
perl -MCPAN -e shell install Debug::LTrace
For more information on module installation, please visit the detailed CPAN module installation guide.