lcpan tips 011: Listing modules you depend on

About this series: a collection of short, daily blog posts about lcpan tips/recipes. Some posts will also end up in the upcoming App::lcpan::Manual::Cookbook POD to be included in the App-lcpan distribution.

About lcpan: an application to download and index a mini CPAN mirror on your local filesystem, so in effect you will have something like your own CPAN with a command-line tool (or perl API) to query and extract information from your mirror. I find it perfect for my own personal use when working offline.

If you happen to be a CPAN author (and if you don’t, why not start now?) you can list all the modules that your distributions depend on using the subcommand author-deps. This subcommand is not that different from deps but instead of looking at dependencies of a single distribution, author-deps collects all your distributions and retrieves the dependencies information from all those distributions. Example:

% lcpan author-deps PERLANCAR ;# list all the modules that I depend on

There are a few options like filtering only core or non-core modules, filtering only dependencies for certain phase and relationship, and filtering only modules from certain authors (or not from certain authors).

There’s another related subcommand you might find interested if you happen to have more than one distribution on CPAN (and if you only have one, why not start uploading more?): author-deps-by-dependent-count. This is exactly like author-deps but for each module will count the number of your distributions that depend on it. So, at the top of the result list you’ll see modules that you “most depend on” (use over and over again across distributions).

Here’s an example of result for my distributions:

% lcpan author-deps-by-dependent-count perlancar
+--------------------------------------------------------+-----------+------------+---------+-----------------+
| module                                                 | author    | version    | is_core | dependent_count |
+--------------------------------------------------------+-----------+------------+---------+-----------------+
| Log::Any::IfLOG                                        | PERLANCAR | 0.07       | 0       | 123             |
| Perinci::CmdLine::Any                                  | PERLANCAR | 0.12       | 0       | 101             |
| strict                                                 | SHAY      | 1.09       | 1       | 77              |
| warnings                                               | SHAY      | 1.34       | 0       | 77              |
| experimental                                           | LEONT     | 0.016      | 0       | 69              |
| Dist::Zilla                                            | RJBS      | 5.043      | 0       | 46              |
| Complete::Util                                         | PERLANCAR | 0.45       | 0       | 36              |
| JSON                                                   | MAKAMAKA  | 2.90       | 0       | 36              |
| Exporter                                               | TODDR     | 5.72       | 1       | 29              |
| Data::Dmp                                              | PERLANCAR | 0.14       | 0       | 25              |
| Perinci::Sub::Util                                     | PERLANCAR | 0.45       | 0       | 25              |
| File::Which                                            | PLICEASE  | 1.19       | 0       | 24              |
| WordList                                               | PERLANCAR | 0.001001   | 0       | 24              |
| Module::Path::More                                     | PERLANCAR | 0.30       | 0       | 22              |
| Perinci::Sub::Gen::AccessTable                         | PERLANCAR | 0.55       | 0       | 22              |
| File::Slurper                                          | LEONT     | 0.008      | 0       | 21              |
| Module::List                                           | ZEFRAM    | 0.003      | 0       | 21              |
| Perinci::Sub::Normalize                                | PERLANCAR | 0.15       | 0       | 21              |
| Module::Patch                                          | PERLANCAR | 0.22       | 0       | 20              |
| Complete::Common                                       | PERLANCAR | 0.22       | 0       | 19              |
| Moo                                                    | HAARG     | 2.000002   | 0       | 17              |
...

I’m in the middle of a process of listing core modules for my distributions (previously I didn’t), so currently more than half of my distributions do not yet list core prereqs. Over time, core modules like strict or warnings should be at the top since I use them practically always (except when I use Moo or Moose, in which case strict/warnings are already enabled by those modules.)

Filtering out my own modules, we get:

% lcpan author-deps-by-dependent-count perlancar --module-author-isnt perlancar
+-------------------------------------------+-----------+------------+---------+-----------------+
| module                                    | author    | version    | is_core | dependent_count |
+-------------------------------------------+-----------+------------+---------+-----------------+
| strict                                    | SHAY      | 1.09       | 1       | 77              |
| warnings                                  | SHAY      | 1.34       | 0       | 77              |
| experimental                              | LEONT     | 0.016      | 0       | 69              |
| Dist::Zilla                               | RJBS      | 5.043      | 0       | 46              |
| JSON                                      | MAKAMAKA  | 2.90       | 0       | 36              |
| Exporter                                  | TODDR     | 5.72       | 1       | 29              |
| File::Which                               | PLICEASE  | 1.19       | 0       | 24              |
| File::Slurper                             | LEONT     | 0.008      | 0       | 21              |
| Module::List                              | ZEFRAM    | 0.003      | 0       | 21              |
| Moo                                       | HAARG     | 2.000002   | 0       | 17              |
| Capture::Tiny                             | DAGOLDEN  | 0.34       | 0       | 16              |
| utf8                                      | SHAY      | 1.17       | 1       | 16              |
| DBI                                       | TIMB      | 1.634      | 0       | 15              |
| Data::Dump                                | GAAS      | 1.23       | 0       | 15              |
| List::MoreUtils                           | REHSACK   | 0.413      | 0       | 15              |
| Moose                                     | ETHER     | 2.1605     | 0       | 15              |
| DateTime                                  | DROLSKY   | 1.21       | 0       | 14              |
| Log::Any                                  | DAGOLDEN  | 1.038      | 0       | 14              |
...
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s