in reply to find module name from the module archive
G'day Lotus1,
[Firstly, I'm a bit late to the party with this. I started to write some code yesterday, was interrupted, and only got back to it about 24 hours later.]
"This seems likely to break in future use."
There are a number of issues, especially if you were hoping to turn this into a general solution. Here are the main ones as I see them. I acknowledge that, in some cases, I'm repeating what others have already said.
For testing, I chose the following distributions:
For additional testing, I made .tar.bz2, .tgz and .tar versions of libwww-perl-6.15 and .tar.gz, .tgz and .tar versions of Qt4-0.99.0.
Here's my test code:
#!/usr/bin/env perl use 5.014; use strict; use warnings; use Archive::Tar; use List::Util qw{sum0}; use Test::More; my @test_data = ( { tarball_name_base => 'libwww-perl-6.15', filename_extensions => [qw{.tar.gz .tar.bz2 .tgz .tar}], expected_modules => [qw{ LWP LWP::Authen::Basic LWP::Authen::Digest LWP::Authen::Nt +lm LWP::ConnCache LWP::Debug LWP::DebugFile LWP::MemberMixin LWP::Protocol LWP::Protocol::GHTTP LWP::Protocol::cpan LWP::Protocol::data LWP::Protocol::file LWP::Protocol::ftp LWP::Protocol::gopher LWP::Protocol::http LWP::Protocol::loopback LWP::Protocol::mailto LWP::Protocol::nntp LWP::Protocol::nogo LWP::RobotUA LWP::Simple LWP::UserAgent }], }, { tarball_name_base => 'Qt4-0.99.0', filename_extensions => [qw{.tar.bz2 .tar.gz .tgz .tar}], expected_modules => [qw{ Phonon QImageBlitz Qsci Qt3Support4 QtCore4 QtCore4::class +info QtCore4::debug QtCore4::isa QtCore4::signals QtCore4::slot +s QtDBus4 QtDeclarative4 QtGui4 QtHelp4 QtMultimedia4 QtNetw +ork4 QtOpenGL4 QtScript4 QtSql4 QtSvg4 QtTest4 QtUiTools4 QtWeb +Kit4 QtXml4 QtXmlPatterns4 Qwt }], }, { tarball_name_base => 'Authen-SASL-Perl-NTLM-0.003', filename_extensions => [qw{.tar.gz}], expected_modules => [qw{Authen::SASL::Perl::NTLM}], }, ); plan tests => sum0 map { scalar @{$_->{filename_extensions}} } @test_d +ata; my $map_re = qr{(?x: ^ .*? \b lib / ( [^.]+ ) )}; my $grep_re = qr{(?x: ^ .*? \b lib / [^.]+ [.] pm )}; for my $tarball_test (@test_data) { for my $filename_extension (@{$tarball_test->{filename_extensions} +}) { my $tarball = $tarball_test->{tarball_name_base} . $filename_e +xtension; my $tar = Archive::Tar::->new(); $tar->read($tarball, '', {filter => qr{(?x: ^ [^/]* /? MANIFES +T $ )}}); my @manifest_lines = split /\R+/, $tar->get_content($tar->list +_files()); my @modules = map { (/$map_re/)[0] =~ s{/}{::}gr } grep { /$grep_re/ } @manifest_lines; is("@{[sort @modules]}", "@{[sort @{$tarball_test->{expected_modules}}]}", "Testing: $tarball"); } }
All of the expected_modules lists were taken directly from the distribution pages already linked to.
Here's the results:
1..9 ok 1 - Testing: libwww-perl-6.15.tar.gz ok 2 - Testing: libwww-perl-6.15.tar.bz2 ok 3 - Testing: libwww-perl-6.15.tgz ok 4 - Testing: libwww-perl-6.15.tar ok 5 - Testing: Qt4-0.99.0.tar.bz2 ok 6 - Testing: Qt4-0.99.0.tar.gz ok 7 - Testing: Qt4-0.99.0.tgz ok 8 - Testing: Qt4-0.99.0.tar ok 9 - Testing: Authen-SASL-Perl-NTLM-0.003.tar.gz
— Ken
|
|---|