Permalink
Browse files

initial import of Devel-TraceUse 1.00 from CPAN

git-cpan-module:   Devel-TraceUse
git-cpan-version:  1.00
git-cpan-authorid: CHROMATIC
git-cpan-file:     authors/id/C/CH/CHROMATIC/Devel-TraceUse-1.00.tar.gz
  • Loading branch information...
chromatic authored and schwern committed Jul 11, 2006
0 parents commit 59801b9c0a94be556eef8f4ca8a3a32abeb4639d
Showing with 456 additions and 0 deletions.
  1. +50 −0 Build.PL
  2. +4 −0 Changes
  3. +15 −0 MANIFEST
  4. +24 −0 META.yml
  5. +53 −0 README
  6. +160 −0 lib/Devel/TraceUse.pm
  7. +17 −0 t/00-load.t
  8. +48 −0 t/boilerplate.t
  9. +9 −0 t/developer/pod-coverage.t
  10. +6 −0 t/developer/pod.t
  11. +9 −0 t/lib/Child.pm
  12. +8 −0 t/lib/Parent.pm
  13. +6 −0 t/lib/Sibling.pm
  14. +32 −0 t/report.t
  15. +15 −0 t/tracer.pl
@@ -0,0 +1,50 @@
+#! perl
+
+use Module::Build;
+
+use strict;
+use warnings;
+
+my $class = Module::Build->subclass(
+ class => 'Module::Build::FilterTests',
+ code => <<'END_HERE',
+
+ use File::Glob;
+ use File::Spec::Functions;
+
+ sub ACTION_disttest
+ {
+ my $self = shift;
+ local $ENV{PERL_RUN_ALL_TESTS} = 1;
+ $self->SUPER::ACTION_disttest( @_ );
+ }
+
+ sub find_test_files
+ {
+ my $self = shift;
+ my $tests = $self->SUPER::find_test_files( @_ );
+
+ return $tests unless $ENV{PERL_RUN_ALL_TESTS};
+
+ my $test_pattern = catfile(qw( t developer *.t ) );
+ unshift @$tests, File::Glob::bsd_glob( $test_pattern );
+ return $tests;
+ }
+END_HERE
+);
+
+my $builder = $class->new(
+ module_name => 'Devel::TraceUse',
+ license => 'perl',
+ dist_author => 'chromatic <chromatic@wgz.org>',
+ dist_version_from => 'lib/Devel/TraceUse.pm',
+ build_requires => {
+ 'Test::More' => 0,
+ },
+ add_to_cleanup => [ 'Devel-TraceUse-*' ],
+ no_index => {
+ package => [ 'Foo::Bar', ]
+ },
+);
+
+$builder->create_build_script();
@@ -0,0 +1,4 @@
+Revision history for Devel-TraceUse
+
+1.00 Tue Jul 11 04:45:53 UTC 2006 ($Rev$, $Author$)
+ First version, released on an unsuspecting world.
@@ -0,0 +1,15 @@
+Build.PL
+Changes
+MANIFEST
+META.yml # Will be created by "make dist"
+README
+lib/Devel/TraceUse.pm
+t/00-load.t
+t/boilerplate.t
+t/developer/pod.t
+t/developer/pod-coverage.t
+t/lib/Parent.pm
+t/lib/Child.pm
+t/lib/Sibling.pm
+t/report.t
+t/tracer.pl
@@ -0,0 +1,24 @@
+---
+name: Devel-TraceUse
+version: 1.00
+author:
+ - 'chromatic <chromatic@wgz.org>'
+abstract: 'show the modules your program loads, recursively'
+license: perl
+resources:
+ license: http://dev.perl.org/licenses/
+build_requires:
+ Test::More: 0
+provides:
+ DB:
+ file: lib/Devel/TraceUse.pm
+ Devel::TraceUse:
+ file: lib/Devel/TraceUse.pm
+ version: 1.00
+no_index:
+ package:
+ - Foo::Bar
+generated_by: Module::Build version 0.2801
+meta-spec:
+ url: http://module-build.sourceforge.net/META-spec-v1.2.html
+ version: 1.2
53 README
@@ -0,0 +1,53 @@
+Devel::TraceUse
+---------------
+
+Show the modules your program loads, recursively.
+
+An apparently simple program may load a lot of modules. That's useful, but
+sometimes you may wonder exactly which part of your program loads which module.
+
+Devel::TraceUse can analyze a program to see which part used which module. I
+recommend using it from the command line:
+
+ $ perl -d:TraceUse your_program.pl
+
+This will display a tree of the modules ultimately used to run your program.
+(It also runs your program with only a little startup cost all the way through
+to the end.)
+
+ Modules used from your_program.pl:
+ Test::MockObject::Extends, line 6 (0.000514)
+ Test::MockObject, line 6 (0.000408)
+ Scalar::Util, line 9 (0.000521)
+ List::Util, line 12 (0.000393)
+ XSLoader, line 24 (0.000396)
+ UNIVERSAL::isa, line 10 (0.000436)
+ UNIVERSAL, line 8 (0.000247)
+ UNIVERSAL::can, line 11 (0.000428)
+ Test::Builder, line 13 (0.000413)
+ Devel::Peek, line 8 (0.000693)
+
+INSTALLATION
+
+To install this module, run the following commands:
+
+ $ perl Build.PL
+ $ perl ./Build
+ $ perl ./Build test
+ $ sudo perl ./Build install
+
+SUPPORT AND DOCUMENTATION
+
+After installing, you can find documentation for this module with the perldoc
+command.
+
+ $ perldoc Devel::TraceUse
+
+Alternately, read hack #74 in Perl Hacks, published by O'Reilly Media in 2006.
+
+COPYRIGHT AND LICENCE
+
+Copyright (C) 2006 chromatic.
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
@@ -0,0 +1,160 @@
+package DB;
+
+# allow -d:TraceUse loading with this little C++-style no-op
+sub DB {}
+
+package Devel::TraceUse;
+
+use strict;
+use warnings;
+
+use vars '$VERSION';
+$VERSION = '1.00';
+
+use Time::HiRes qw( gettimeofday tv_interval );
+
+BEGIN
+{
+ unshift @INC, \&trace_use unless grep { "$_" eq \&trace_use . '' } @INC;
+}
+
+my @used;
+
+sub trace_use
+{
+ my ( $code, $module ) = @_;
+ ( my $mod_name = $module ) =~ s{/}{::}g;
+ $mod_name =~ s/\.pm$//;
+
+ my ( $package, $filename, $line ) = caller();
+ my $elapsed = 0;
+
+ {
+ local *INC = [ @INC[ 1 .. $#INC ] ];
+ my $start_time = [ gettimeofday() ];
+ eval "package $package; require '$mod_name';";
+ $elapsed = tv_interval($start_time);
+ }
+
+ $package = $filename if $package eq 'main';
+
+ push @used,
+ {
+ 'file' => $package,
+ 'line' => $line,
+ 'time' => $elapsed,
+ 'module' => $mod_name,
+ };
+
+ return;
+}
+
+END
+{
+ my $first = $used[0];
+ my %seen = ( $first->{file} => 1 );
+ my $pos = 1;
+
+ warn "Modules used from $first->{file}:\n";
+
+ for my $mod (@used)
+ {
+ my $message = '';
+
+ if ( exists $seen{ $mod->{file} } )
+ {
+ $pos = $seen{ $mod->{file} };
+ }
+ else
+ {
+ $seen{ $mod->{file} } = ++$pos;
+ }
+
+ my $indent = ' ' x $pos;
+ $message .= "$indent$mod->{module}, line $mod->{line}";
+ $message .= " ($mod->{time})" if $mod->{time};
+ warn "$message\n";
+ }
+}
+
+1;
+__END__
+
+=head1 NAME
+
+Devel::TraceUse - show the modules your program loads, recursively
+
+=head1 SYNOPSIS
+
+An apparently simple program may load a lot of modules. That's useful, but
+sometimes you may wonder exactly which part of your program loads which module.
+
+C<Devel::TraceUse> can analyze a program to see which part used which module.
+I recommend using it from the command line:
+
+ $ B<perl -d:TraceUse your_program.pl>
+
+This will display a tree of the modules ultimately used to run your program.
+(It also runs your program with only a little startup cost all the way through
+to the end.)
+
+ Modules used from your_program.pl:
+ Test::MockObject::Extends, line 6 (0.000514)
+ Test::MockObject, line 6 (0.000408)
+ Scalar::Util, line 9 (0.000521)
+ List::Util, line 12 (0.000393)
+ XSLoader, line 24 (0.000396)
+ UNIVERSAL::isa, line 10 (0.000436)
+ UNIVERSAL, line 8 (0.000247)
+ UNIVERSAL::can, line 11 (0.000428)
+ Test::Builder, line 13 (0.000413)
+ Devel::Peek, line 8 (0.000693)
+
+=head1 AUTHOR
+
+chromatic, C<< <chromatic at wgz.org> >>
+
+=head1 BUGS
+
+Please report any bugs or feature requests to
+C<bug-devel-traceuse at rt.cpan.org>, or through the web interface at
+L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Devel-TraceUse>. We can both track it there.
+
+=head1 SUPPORT
+
+You can find documentation for this module with the perldoc command.
+
+ perldoc Devel::TraceUse
+
+You can also look for information at:
+
+=over 4
+
+=item * I<Perl Hacks>, hack #74
+
+O'Reilly Media, 2006.
+
+=item * AnnoCPAN: Annotated CPAN documentation
+
+L<http://annocpan.org/dist/Devel-TraceUse>
+
+=item * CPAN Ratings
+
+L<http://cpanratings.perl.org/d/Devel-TraceUse>
+
+=item * RT: CPAN's request tracker
+
+L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Devel-TraceUse>
+
+=item * Search CPAN
+
+L<http://search.cpan.org/dist/Devel-TraceUse>
+
+=back
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2006 chromatic, most rights reserved.
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
@@ -0,0 +1,17 @@
+#!perl -T
+
+use Test::More tests => 4;
+
+my @inc_copy = @INC;
+
+use_ok( 'Devel::TraceUse' );
+diag( "Testing Devel::TraceUse $Devel::TraceUse::VERSION, Perl $], $^X" );
+
+is( @INC, @inc_copy + 1, 'using module should add path to @INC' );
+is( ref $INC[0], 'CODE', '... a coderef to the start' );
+
+Devel::TraceUse->import();
+is( @INC, @inc_copy + 1, '... but should add it only once' );
+
+# suppress diagnostic output at the end
+$SIG{__WARN__} = sub {};
@@ -0,0 +1,48 @@
+#!perl -T
+
+use strict;
+use warnings;
+use Test::More tests => 3;
+
+sub not_in_file_ok {
+ my ($filename, %regex) = @_;
+ open my $fh, "<", $filename
+ or die "couldn't open $filename for reading: $!";
+
+ my %violated;
+
+ while (my $line = <$fh>) {
+ while (my ($desc, $regex) = each %regex) {
+ if ($line =~ $regex) {
+ push @{$violated{$desc}||=[]}, $.;
+ }
+ }
+ }
+
+ if (%violated) {
+ fail("$filename contains boilerplate text");
+ diag "$_ appears on lines @{$violated{$_}}" for keys %violated;
+ } else {
+ pass("$filename contains no boilerplate text");
+ }
+}
+
+not_in_file_ok(README =>
+ "The README is used..." => qr/The README is used/,
+ "'version information here'" => qr/to provide version information/,
+);
+
+not_in_file_ok(Changes =>
+ "placeholder date/time" => qr(Date/time)
+);
+
+sub module_boilerplate_ok {
+ my ($module) = @_;
+ not_in_file_ok($module =>
+ 'the great new $MODULENAME' => qr/ - The great new /,
+ 'boilerplate description' => qr/Quick summary of what the module/,
+ 'stub function definition' => qr/function[12]/,
+ );
+}
+
+module_boilerplate_ok('lib/Devel/TraceUse.pm');
@@ -0,0 +1,9 @@
+#!perl -T
+
+use Test::More;
+eval "use Test::Pod::Coverage 1.04";
+plan skip_all =>
+ "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@;
+plan skip_all =>
+ "No user servicable parts inside. This Kwalitee metric is a bit silly.";
+all_pod_coverage_ok();
@@ -0,0 +1,6 @@
+#!perl -T
+
+use Test::More;
+eval "use Test::Pod 1.14";
+plan skip_all => "Test::Pod 1.14 required for testing POD" if $@;
+all_pod_files_ok();
Oops, something went wrong.

0 comments on commit 59801b9

Please sign in to comment.