Getting "specific" modules from a CPAN data file?

Given the file with the CPAN mailing list (for example, Acme-Chef-1.01.tar.gz ), which algorithm determines which versions of the modules are β€œdefined” (or presented) in the dist file?

For example, in the 02packages.details.txt file, 02packages.details.txt are four lines that correspond to this dist file:

 Acme::Chef 1.01 S/SM/SMUELLER/Acme-Chef-1.01.tar.gz Acme::Chef::Container 1.00 S/SM/SMUELLER/Acme-Chef-1.01.tar.gz Acme::Chef::Ingredient 1.00 S/SM/SMUELLER/Acme-Chef-1.01.tar.gz Acme::Chef::Recipe 1.00 S/SM/SMUELLER/Acme-Chef-1.01.tar.gz 

Basically I want to know how these lines are generated.

Is the procedure similar:

  • find all .pm files in dist file
  • download each of the .pm files and print ${ "${pkg}::VERSION"} , where $pkg is the package name corresponding to the name of the .pm file (i.e. if the file name is .pm Foo/Bar.pm , then $pkg Foo::Bar .)

Is there any code that performs this indexing procedure?

Do you really need to download the module to determine what version it is?

+4
source share
1 answer

The actual code that does this for PAUSE is on GitHub here . Routines that parse package and version declarations are located in the lib / PAUSE / pmfile.pm folder ( packages_per_pmfile and parse_version ). This is authoritative as far as CPAN does, but it is not the code that you would ever want to use for yourself - PAUSE is almost 20 years old, and even after a recent cleanup it is still pretty rude.

Instead, check out Module :: Metadata . You give it a file, and it provides a fairly simple interface for detecting package names inside this file and their versions.

It is about as simple:

 my $mm = Module::Metadata->new_from_file("My/Module.pm"); for my $package ($mm->packages_inside) { print "$package: ", $mm->version($package), "\n"; } 

And really, this "one-line" works:

 find Acme-Chef-1.01 -name \*.pm \ | perl -MModule::Metadata -ln \ -e 'my $mm = Module::Metadata->new_from_file($_); ' \ -e 'print "$_: ", $mm->version($_) for $mm->packages_inside' \ | sort 

and outputs:

 Acme::Chef: 1.01 Acme::Chef::Container: 1.00 Acme::Chef::Ingredient: 1.00 Acme::Chef::Recipe: 1.00 
+4
source

Source: https://habr.com/ru/post/1497353/


All Articles