Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

As some of you know, I'm doing an audit of my code. Part of that audit is finding what modules my modules use and what modules I have written are used by other modules I have written. If I ever get things nice enough in some of my modules, I might one day put a few up on CPAN. However, I need to know what modules my modules use so I can include them in the install if the user does not already have. Like, if I use Lingua::EN::Inflect in a module (or group of modules), it would need to be installed if the user does not have it already. At least I think so.

I came up with the following code to find the information but there might be a better way.

Update: I put the updated code I used here: Re: Finding what modules use and what uses the modules. Your options looked interesting but did not differentiate things the way I wanted.

#!/usr/bin/perl use strict; use warnings; use File::Find; 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 $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 (<$fh>) { chomp; if ($_ =~ s/^use ((:|\w)+)(.+)/$1/) { push @{$modules->{$file_convert}{'uses'}}, $1; # what modules + the module uses push @{$modules->{$1}{'used by'}}, $file_convert; # what modules + use this module } } } my $in = shift; use Data::Dumper; print Dumper($modules->{$in});

Here is example output.

me@office:~$ perl Documents/scripts/ 'RolePlaying::R +andom' $VAR1 = { 'used by' => [ 'RolePlaying::CharacterMutation', 'RolePlaying::Random::Range', 'RolePlaying::Random::Time', 'RolePlaying::Random::SpecialAttack', 'RolePlaying::Random::Title', 'RolePlaying::Random::WildPsionics', 'RolePlaying::Random::Descriptor', 'RolePlaying::Random::Spell', 'RolePlaying::Random::SavingThrow', 'RolePlaying::Random::Color', 'RolePlaying::Random::Monster', 'RolePlaying::Random::GemMetalJewelry', 'RolePlaying::Random::Thing', 'RolePlaying::Random::Weapon', 'RolePlaying::Random::Size', 'RolePlaying::Random::Food', 'RolePlaying::Random::Misc', 'RolePlaying::Random::Event', 'RolePlaying::Random::Water', 'RolePlaying::Random::Class', 'RolePlaying::Random::MagicItem', 'RolePlaying::Random::Color::VisiBone', 'RolePlaying::Random::Body::Function', 'RolePlaying::Random::Body::Modification' ], 'uses' => [ 'strict', 'warnings', 'Exporter', 'List::Util' ] };

If you know of a better way that will give me deeper or more sophisticated results, I am interested.

No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
Lady Aleena

In reply to Finding what modules use and what uses the modules by Lady_Aleena

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (4)
    As of 2020-08-08 20:24 GMT
    Find Nodes?
      Voting Booth?
      Which rocket would you take to Mars?

      Results (53 votes). Check out past polls.