Properly find CPAN provided modules #2125
Open
+87
−19
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR aims to solve issue #2124.
Here is a link to the metacpan api url that is currently used, searching a module
Dist::Zilla(whos distribution provides many modules): https://fastapi.metacpan.org/v1/module/Dist::Zilla . Notice that there is no field for provided modules. If instead we search for a release of theDist-Zilladistribution, we see a long list of provided modules under theprovidesfield: https://fastapi.metacpan.org/v1/release/Dist-Zilla .I created a function
search_provided_modules()that finds all the provided modules of some version of some distribution. This function is instead used to set theself.providesfield in theinput()function. Thereleaseapi does not show the provided modules versions, so I used different but equivalent logic to search themoduleapi for all modules that belong to the given distribution version. This allows us to also determine the module version (which isn't necessarily) the same as the distribution version.While I was at it I updated the
search()function, renaming itsearch_module(), and added an optional parameter to specify which version of the module to search. The HTTP GET method for the metacpan api url that was being used only finds the latest version of the module. To find a specific version, I updated the code to use the HTTP POST method for the metacpan api that allows for more powerful queries. The query I used is the same except that if theversionparameter is defined it queries for that specific version of the module instead of the latest version.Another thing worth noting is that I found that we had an unused variable named
depthat was defined in theinput()function, and was created by a call tosearch(). I deleted this variable. Here is a link to the variable definition.I added new tests to
cpan_spec.rbfor this newsearch_provided_modules()function, and also updated an exisiting test to checkself.providesafter callinginput().Issue #2124 showed that currently fpm did not find the correct provided modules. Here are the same commands that were given in the issue, showing that this PR fixed the problem (cut off as there are over 140 entries):