From 9e524ed893ae54c43971936241fae257d45e1573 Mon Sep 17 00:00:00 2001 From: Mark Jason Dominus Date: Mon, 6 Sep 1999 20:54:19 -0800 Subject: [PATCH] initial import of Devel-Trace 0.10 from CPAN git-cpan-module: Devel-Trace git-cpan-version: 0.10 git-cpan-authorid: MJD git-cpan-file: authors/id/M/MJ/MJD/Devel-Trace-0.10.tar.gz --- Changes | 5 ++ MANIFEST | 7 +++ Makefile.PL | 7 +++ README | 81 ++++++++++++++++++++++++++++ Trace.pm | 150 ++++++++++++++++++++++++++++++++++++++++++++++++++++ sample | 14 +++++ test.pl | 21 ++++++++ 7 files changed, 285 insertions(+) create mode 100644 Changes create mode 100644 MANIFEST create mode 100644 Makefile.PL create mode 100644 README create mode 100644 Trace.pm create mode 100755 sample create mode 100755 test.pl diff --git a/Changes b/Changes new file mode 100644 index 0000000..3bda0a9 --- /dev/null +++ b/Changes @@ -0,0 +1,5 @@ +Revision history for Perl extension Devel::Trace. + +0.01 Mon Sep 6 21:32:55 1999 + - original version; created by h2xs 1.19 + diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..a556e0b --- /dev/null +++ b/MANIFEST @@ -0,0 +1,7 @@ +Changes +MANIFEST +Makefile.PL +Trace.pm +test.pl +sample +README diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..982d3ff --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,7 @@ +use ExtUtils::MakeMaker; +# See lib/ExtUtils/MakeMaker.pm for details of how to influence +# the contents of the Makefile that is written. +WriteMakefile( + 'NAME' => 'Devel::Trace', + 'VERSION_FROM' => 'Trace.pm', # finds $VERSION +); diff --git a/README b/README new file mode 100644 index 0000000..d707cdb --- /dev/null +++ b/README @@ -0,0 +1,81 @@ +NAME + Devel::Trace - 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::Trace::TRACE = 1; # Enable + $Devel::Trace::TRACE = 0; # Disable + + + or + + Devel::Trace::trace('on'); # Enable + Devel::Trace::trace('off'); # Disable + + + `Devel::Trace' exports the `trace' function if you ask it to: + + import Devel::Trace 'trace'; + + + Then if you want you just say + + trace 'on'; # Enable + trace 'off'; # Disable + + +TODO + * You should be able to send the trace output to the filehandle of your + choice. + + * You should be able to specify the format of the output. + + * You should be able to get the output into a string. + + + We'll see. + +Author + Mark-Jason Dominus (`mjd-perl-trace+@plover.com'), Plover Systems co. + + See the `Devel::Trace.pm' Page at http://www.plover.com/~mjd/perl/Trace + for news and upgrades. + diff --git a/Trace.pm b/Trace.pm new file mode 100644 index 0000000..7b758a6 --- /dev/null +++ b/Trace.pm @@ -0,0 +1,150 @@ +# -*- perl -*- + +package Devel::Trace; +$VERSION = '0.10'; +$TRACE = 1; + +# This is the important part. The rest is just fluff. +sub DB::DB { + return unless $TRACE; + my ($p, $f, $l) = caller; + my $code = \@{"::_<$f"}; + print STDERR ">> $f:$l: $code->[$l]"; +} + + +sub import { + my $package = shift; + foreach (@_) { + if ($_ eq 'trace') { + my $caller = caller; + *{$caller . '::trace'} = \&{$package . '::trace'}; + } else { + use Carp; + croak "Package $package does not export `$_'; aborting"; + } + } +} + +my %tracearg = ('on' => 1, 'off' => 0); +sub trace { + my $arg = shift; + $arg = $tracearg{$arg} while exists $tracearg{$arg}; + $TRACE = $arg; +} + +1; + + +=head1 NAME + +Devel::Trace - Print out each line before it is executed (like C) + +=head1 SYNOPSIS + + perl -d:Trace program + +=head1 DESCRIPTION + +If you run your program with C, 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 C 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 C<-x> option. + +=head1 DETAILS + +Inside your program, you can enable and disable tracing by doing + + $Devel::Trace::TRACE = 1; # Enable + $Devel::Trace::TRACE = 0; # Disable + +or + + Devel::Trace::trace('on'); # Enable + Devel::Trace::trace('off'); # Disable + + +C exports the C function if you ask it to: + + import Devel::Trace 'trace'; + +Then if you want you just say + + trace 'on'; # Enable + trace 'off'; # Disable + + +=head1 TODO + +=over 4 + +=item * + +You should be able to send the trace output to the filehandle of your choice. + +=item * + +You should be able to specify the format of the output. + +=item * + +You should be able to get the output into a string. + +=back + +We'll see. + +=head1 Author + +=begin text + +Mark-Jason Dominus (C), Plover Systems co. + +See the C Page at http://www.plover.com/~mjd/perl/Trace +for news and upgrades. + +=end text + +=begin man + +Mark-Jason Dominus (C), Plover Systems co. + +See the C Page at http://www.plover.com/~mjd/perl/Trace +for news and upgrades. + +=end man + +=begin html +

Mark-Jason Dominus (mjd-perl-trace@plover.com), Plover Systems co.

+

See The Devel::Trace.pm Page for news and upgrades.

+ +=end html + + +=cut + diff --git a/sample b/sample new file mode 100755 index 0000000..5a01f5c --- /dev/null +++ b/sample @@ -0,0 +1,14 @@ +#!/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; +} \ No newline at end of file diff --git a/test.pl b/test.pl new file mode 100755 index 0000000..5a86221 --- /dev/null +++ b/test.pl @@ -0,0 +1,21 @@ +# Before `make install' is performed this script should be runnable with +# `make test'. After `make install' it should work as `perl test.pl' + +######################### We start with some black magic to print on failure. + +BEGIN { $| = 1; print "1..1\n"; } +END {print "not ok 1\n" unless $loaded;} +use Devel::Trace; +$loaded = 1; +print "ok 1\n"; + +######################### End of black magic. + +open S, "< sample" or die "Couldn't open sample demo file: $!; aborting"; +print while ; +close S; +print "\n"; +print "Press enter to execute this file. \n"; +; +system("perl -I./blib/lib -d:Trace sample"); +$? and die "Problem running sample program: $? exit status\n";