Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Finding what modules use and what uses the modules

by Lady_Aleena (Curate)
on May 31, 2017 at 09:45 UTC ( #1191682=note: print w/replies, xml ) Need Help??

in reply to Finding what modules use and what uses the modules

I am putting the updated code up so you can all see how I got what I wanted.

#!/usr/bin/perl use strict; use warnings; use File::Find; use Data::Dumper; use Util::Line qw(line); my @files; sub wanted { my $file = $_ =~/.pm$/ ? $File::Find::name : undef; push @files, $file if $file; } my @directories = ('/home/me/Documents/'); find(\&wanted, @directories); my $module_directory = $directories[0].'www/files/lib/'; my @my_modules = map { my $file = $_; $file =~ s/$module_directory(.+) +\.pm/$1/; $file =~ s/\//::/g; $file; } @files; my $modules; for my $file (@files) { open my $fh, '<', $file or die "$file: $!"; my $file_convert = $file; $file_convert =~ s/$module_directory(.+)\.pm/$1/; $file_convert =~ s/\//::/g; while (my $line = <$fh>) { chomp($line); if ($line =~ s/^use ((:|\w)+)(.+)/$1/) { push @{$modules->{$file_convert}{'uses'}{'mine'}}, $1 if gr +ep(/$line/, @my_modules); # what modules the module uses push @{$modules->{$file_convert}{'uses'}{'not mine'}}, $1 if !gr +ep(/$line/, @my_modules); # what modules the module uses push @{$modules->{$1}{'used by'}}, $file_convert; # what modules + use this module } } } my $in = shift; my @ins = grep(/.*$in.*/, @my_modules); for (sort @ins) { my $mod = $modules->{$_}; line(0, $_); if ($mod->{'uses'}) { my $use = $mod->{'uses'}; line(1, "$_ uses"); if ($use->{'mine'}) { line(2, "My modules"); line(3, $_) for sort @{$use->{'mine'}}; } if ($use->{'not mine'}) { line(2, "Other modules"); line(3, $_) for @{$use->{'not mine'}}; } } if ($mod->{'used by'}) { line(1, "$_ used by"); line(2, $_) for sort @{$mod->{'used by'}}; } print "\n"; }

Here is example output.

Base::Data Base::Data uses My modules # it uses one of my modules Base::Path Other modules # it uses several modules that are not mine strict warnings Exporter File::Basename File::Spec List::Util Base::Data used by # it is used by all of these modules Base::LineMagic Base::Menu Base::Page HTML::Forms Movie People RolePlaying::AssetCost RolePlaying::Character::AbilityScores RolePlaying::Character::Class RolePlaying::Character::GameTable::Psionics RolePlaying::Character::GameTable::SpellProgression RolePlaying::Monster RolePlaying::Random::Weapon RolePlaying::Random::WildPsionics RolePlaying::SpellList RolePlaying::Spellbook RolePlaying::WordFind Util::ExternalLinks
No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
Lady Aleena

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1191682]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2017-07-22 14:19 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (340 votes). Check out past polls.