Devel::Quick - Write single-step debugger one-liners easily (DB::DB)
version 0.08
Devel::Trace in one line:
perl -d:Quick='print ">> $filename:$line $code"' prog.pl
The above, with strict checking enabled (not default):
perl -d:Quick=-strict,'print ">> $filename:$line $code"' prog.pl
Or shortened:
perl -d:Quick=-s,'print ">> $filename:$line $code"' prog.pl
The above, but start stepping immediately (look at code in "use ..." statements)
perl -d:Quick=-begin,'print ">> $filename:$line $code"' prog.pl
perl -d:Quick=-b,'print ">> $filename:$line $code"' prog.pl
You can combine opts:
perl -d:Quick=-s,-b,'print ">> $filename:$line $code"' prog.pl
If you need '-' as the first character in your code, use a ';':
perl -d:Quick='; -1 * 2;' prog.pl
This module allows you to write simple on-the-fly DB::DB line debuggers easily. It injects the following code around the code passed to its import method and eval's it in:
DB::DB
package DB; use strict; use warnings; $DB::single = 1; sub DB { # Get who called us my ($package, $filename, $line) = caller(0); # Get the rest from the context of who called us my (undef, undef, undef, $subroutine, $hasargs, $wantarray, $evaltext, $is_require, $hints, $bitmask, $hinthash) = caller(1); return if $package && $package eq 'Devel::Quick'; my $args = \@_; my $code; { no strict 'refs'; $code = @{"::_<$filename"}[$line]; } no strict; <<CODE>> }
By default, warnings are enabled but strict mode is disabled. If you want strict, the first argument to import should be -s or -strict.
-s
-strict
By default, tracing also starts after compile time. This means that code in use statements will not be seen. If you want to trace into use statements, use the -b or -begin flag.
-b
-begin
If you need to pass a - as the first character in the Perl code, you'll need to inject a semi-colon (;) before it like so:
-
A bunch of varibales are provided by default for ease of use, including all variables returned by "caller" in perlfunc, the source code that's about to be executed, and arguments to a subroutine if the code being executed is from one. All described below.
See "caller" in perlfunc for a description of these.
$package
$filename
$line
$subroutine
$hasargs
$wantarray
$evaltext
$is_require
$hints
$bitmask
$hinthash
The variable $code contains the line of source code about to be executed. This is provided by @{"_<$filename"}. See perldebguts for more information.
@{"_<$filename"}
$args is simply a reference to @_ that the code that is about to be executed can see. This is only relevant within subroutines. $hasargs may tell you if this is filled in or not, or just check @$args.
@_
Changing the underlying values will affect what the current subroutine sees.
Matthew Horsfall (alh) - <WolfSage@gmail.com>
To install Devel::Quick, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Devel::Quick
CPAN shell
perl -MCPAN -e shell install Devel::Quick
For more information on module installation, please visit the detailed CPAN module installation guide.