perl - getting "defined" modules from a CPAN dist file? -
given cpan dist file (e.g. acme-chef-1.01.tar.gz
), algorithm determine module-versions "defined" (or present) in dist file?
for instance, in 02packages.details.txt
file, there 4 lines correspond 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
i want know how lines generated.
is procedure like:
- find of
.pm
files in dist file - load each of
.pm
files , print out${ "${pkg}::version"}
$pkg
package name corresponding.pm
file name (i.e. if.pm
file namefoo/bar.pm
$pkg
foo::bar
.)
is there code indexing procedure?
do have load module in order determine version is?
the actual code pause on github here. subroutines parse package , version declarations in lib/pause/pmfile.pm (packages_per_pmfile
, parse_version
). authoritative far happens make cpan work, it's not code you'd ever want use — pause 20 years old , after recent cleanup it's still pretty gross.
instead, @ module::metadata. give file, , provides pretty simple interface discover names of packages inside of file , versions might be.
it's simple as:
my $mm = module::metadata->new_from_file("my/module.pm"); $package ($mm->packages_inside) { print "$package: ", $mm->version($package), "\n"; }
and indeed "one-liner" works:
find acme-chef-1.01 -name \*.pm \ | perl -mmodule::metadata -ln \ -e 'my $mm = module::metadata->new_from_file($_); ' \ -e 'print "$_: ", $mm->version($_) $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
Comments
Post a Comment