in reply to Re^2: CPAN modules for inspecting a Perl distribution?
in thread CPAN modules for inspecting a Perl distribution?

I'm the author of Devel::Examine::Subs, so if you have any issues or questions, feel free to ask away here, or email me using my CPAN page's address.

  • Comment on Re^3: CPAN modules for inspecting a Perl distribution?

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

    I'll bite :) download examine-subs.pl, install the prereqs if you don't have them yet and run it on your site_perl:

    $ cpan Data::Peek Devel::Examine::Subs Digest::SHA SourceCode::LineCou +nter::Perl String::CommonPrefix $ perl examine-subs --site -v : : long wait : /pro/lib/perl5/site_perl/5.28.0/Tk/DHList_v1.pm /pro/lib/perl5/site_perl/5.28.0/Tk/DTree.pm /pro/lib/perl5/site_perl/5.28.0/Tk/DiffText.pm /pro/lib/perl5/site_perl/5.28.0/Tk/FileDialog.pm Can't call method "serialize" on an undefined value at /pro/lib/perl5/ +site_perl/5.28.0/Devel/Examine/Subs.pm line 769. Exit 255

    Enjoy, Have FUN! H.Merijn

      Hey there Tux,

      I'll gladly try to repro, but the link you specified throws: "The requested URL was not found on this server.".

      Could you paste the code here, or correct the link?

      Thanks,

      -stevieb

        I didn't notice that Tux actually Private Messaged me with a working link. I only noticed it after another astute Monk pointed out there was a tag missing in the link.

        Here's a working link to the code: https://tux.nl/Files/examine-subs.pl.

        Here, inline is the actual code, just in case. I'll now go in pursuit of figuring out where the issue may lie. Hopefully it isn't within my code, but if it is, I'm always good at acknowledging and accepting mistakes. If the issue isn't in my code, I will do my best as always to find out what the issue is, and assign a ticket or contact whoever is responsible nonetheless :)

        #!/pro/bin/perl use 5.18.2; use warnings; our $VERSION = "0.02 - 20181015"; our $CMD = $0 =~ s{.*/}{}r; sub usage { my $err = shift and select STDERR; say "usage: $CMD [-v] [file|folder] ..."; say " $CMD --core | --site"; exit $err; } # usage use Getopt::Long qw(:config bundling); GetOptions ( "help|?" => sub { usage (0); }, "V|version" => sub { say "$CMD [$VERSION]"; exit 0; }, "c|core!" => \ my $opt_c, "s|site!" => \ my $opt_s, "v|verbose:1" => \(my $opt_v = 0), ) or usage (1); use Config; use Cwd; use Data::Peek; use Devel::Examine::Subs; use Digest::SHA qw(sha256_hex); use File::Find; use SourceCode::LineCounter::Perl; use String::CommonPrefix qw(common_prefix); my @loc = @ARGV; $opt_c and push @loc, $Config{privlib}; $opt_s and push @loc, $Config{sitelib}; @loc or @loc = (getcwd); my %file; my %seen; # Find all .pm and .pl files. (no .PL or .xs) find (sub { m/\.p[ml]$/ or return; m/^\./ || -l and return; # No symlinks or dot-files $File::Find::dir =~ m{\b(?:sandbox|tmp)(?:/|$)} and return; $seen{(lstat)[1]}++ and return; # dup on inode (hard-link) my $sha = sha256_hex ($_); $seen{$sha}++ and return; # dup on SHA $file{$File::Find::name} = $sha; }, @loc); my $pfx = common_prefix (keys %file); my %stats; for my $file (sort keys %file) { $opt_v and say $file; my $name = $file =~ s/^$pfx//r; my $flc = SourceCode::LineCounter::Perl->new; $flc->count ($file); $stats{$name} = { name => $name, file => $file, lines => $flc->total, blank => $flc->blank, doc => $flc->documentation, cmnt => $flc->comment, loc => 0, nobj => 0, }; # Now analyse subs my $des = Devel::Examine::Subs->new (file => $file); unless ($des) { say STDERR "Cannot analyse $name"; next; } my $objs = $des->objects; unless ($objs) { say STDERR "File $name has no objects"; next; } foreach my $obj (@{$des->objects}) { $stats{$name}{nobj}++; my $slc = SourceCode::LineCounter::Perl->new; $slc->count (\do { join "\n" => @{$obj->code} }); my $loc = $slc->code; $stats{$name}{loc} += $loc; push @{$stats{$name}{obj}}, { name => $obj->name, loc => $loc, lines => $slc->documentation, cmnt => $slc->comment, blnk => $slc->blank, doc => $slc->documentation, }; } } delete $SIG{__WARN__}; delete $SIG{__DIE__}; my @sum; say " subs lines LOC doc blank File"; say "----- ------- ------- ------ ------ ---------------------------- +----------"; for (sort { $b->{nobj} <=> $a->{nobj} || $b->{loc} <=> $a->{loc} } val +ues %stats) { printf "%5d %7d %7d %6s %6d %s\n", $_->{nobj}, $_->{lines}, $_->{loc}, $_->{doc} + $_->{cmnt}, $_->{b +lank}, $_->{name}; $sum[0] += $_->{nobj}; $sum[1] += $_->{lines}; $sum[2] += $_->{loc}; $sum[3] += $_->{doc} + $_->{cmnt}; $sum[4] += $_->{blank}; } say "----- ------- ------- ------ ------ ---------------------------- +----------"; printf "%5d %7d %7d %6s %6d\n", @sum;