Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Finding what modules use and what uses the modules

by Lady_Aleena (Priest)
on May 31, 2017 at 09:45 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-16 19:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found