Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: CPAN modules for inspecting a Perl distribution?

by nysus (Parson)
on Oct 13, 2018 at 19:08 UTC ( [id://1223973]=note: print w/replies, xml ) Need Help??


in reply to CPAN modules for inspecting a Perl distribution?

Here's a script I hacked together that gives me a basic report on a distribution. It provides a simple listing of each module, sorted by modules with most lines of code along with the number of subroutines in the module, followed by a summary report.

#! /usr/bin/env perl use strict; use warnings; use Devel::Examine::Subs; use SourceCode::LineCounter::Perl; use Data::Dumper qw(Dumper); my $filename = '/path/to/module/directory'; my $des = Devel::Examine::Subs->new( file => $filename ); my $files = $des->all( ); my %subs = (); my $subroutine_total = 0; my $counter = SourceCode::LineCounter::Perl->new; $counter->accumulate(1); for my $file (sort keys %$files) { my $name = $file =~ s/$filename//r; my $old_count = $counter->code; $counter->count( $file ); my $lines_of_code = $counter->code - $old_count; my $number_of_subs = scalar @{$files->{$file}}; $subroutine_total += $number_of_subs; $subs{$name}{sub_names} = join("\n", @{$files->{$file}}); $subs{$name}{lines_of_code} = $lines_of_code; $subs{$name}{subroutines} = $number_of_subs; } print "File listing:\n================\n"; for my $file (sort { $subs{$b}{lines_of_code} <=> $subs{$a}{lines_of_c +ode} } sort keys %subs) { print $file . "\n"; print "Number of subroutines: " . $subs{$file}{subroutines}; print "\n"; print "Lines of code: " . $subs{$file}{lines_of_code}. "\n"; # print $subs{$file}{sub_names}; print "\n\n"; } print "\nTotal # files: " . scalar (keys %subs); print "\nTotal # subroutines: " . $subroutine_total; print "\nTotal # lines: " . $counter->total; print "\nTotal # lines of code: " . $counter->code;

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks

Replies are listed 'Best First'.
Re^2: CPAN modules for inspecting a Perl distribution?
by Tux (Canon) on Oct 14, 2018 at 12:23 UTC

    I like your approach, but it gave me a lot of doubles and it took ages. Here's my stab at it

    Thanks for the motivation :)


    Enjoy, Have FUN! H.Merijn

      That's a sweet looking report. I'm going to steal that. Regarding slowness, I timed my script vs. yours:

      My script: real 0m12.515s user 0m11.919s sys 0m0.505s Your script: real 0m15.987s user 0m15.229s sys 0m0.660s

      This was done on the Rex v 1.6.0 module, which is pretty hefty. When you say "doubles," do you mean that some files were reported twice?

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks

        Doubles: it found files in blib as well as the original, of which some were symlinks to files in lib (or similar). My first run was faster than yours, but I noticed that when you add the numbers from the objects of the analysis, the __END__ docs and such are not taken into account for the whole file, which is why I analyze twice: once for the whole file (lines of docs and comments and total lines in the file) and once per object (lines of code). Another slowdown is because of the SHA256, as files might get copied (no link or symlink).

        It is an interesting project though. Have you tried it on your site_perl? For me it crashes halfway with some weird error (after running for 15 minutes), but then again, I do have 2118 modules installed, resulting in 12151 .pm files and 900 .pl files. That'll take a while to complete.


        Enjoy, Have FUN! H.Merijn

      Curious to know what these lines are for:

      delete $SIG{__WARN__}; delete $SIG{__DIE__};

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks

        Try a warn inside the main for loop or after it. Those handlers are "stolen" inside one of the analyzers and are still so after the loop.


        Enjoy, Have FUN! H.Merijn

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1223973]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-23 10:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found