Since the *.pm files live in the subdirectory lib of a CPAN package, I'd do something like
#!/usr/bin/perl use strict; use warnings; use File::Temp qw(tempdir); use File::Find; use File::Spec; my $module_tgz = shift || die "usage: $0 pkgfile\n"; my $dir = tempdir(CLEANUP => 1); system "tar -C $dir -xzf $module_tgz" and die "untaring $module_tgz failed\n"; my ($pkg) = do { opendir my($dh),$dir; grep !/^\.\.?$/, readdir $dh }; my $pkgdir = File::Spec->catfile($dir,$pkg); my $libdir = File::Spec->catfile($dir,$pkg,'lib'); my $makefile = File::Spec->catfile($dir,$pkg,'Makefile.PL'); my $module; if ( -e $makefile) { open my $fh, '<', $makefile or die "Can't read $makefile\n"; FH: while(<$fh>) { if ( /WriteMakefile/ .. /\);/) { /NAME\S?\s*=>\s(?:["']|q+(.))([\w:]+)(?:["']|q+(.))/ and print "Module: ", ($module = $2),"\n" and last FH; } } } print "Module ",($module || '(unknown)')," provides:\n"; find(\&get_mods,$libdir); sub get_mods { if ((my $file = $File::Find::name) =~ s/\.pm$//) { $file =~ s{.*lib/}{}; $file =~ s{/}{::}g; print " $file\n"; } }
...but yes, the approach to extract the module name from the named parameters passed to WriteMakefile probably fails but for the most common case, in which WriteMakefile is passed a named parameter list with the key NAME and it's value on a single line as in:
NAME => q(Foo::Bar),
If extraction of the module fails, then probably the Module name is the shortest one displayed by find(). Or else...
But then, for Debian based Linux distros, there is the debhelper suite, which includes code to extract the package name from a CPAN package. I'm just too lazy to poke around there (not for whipping up a script, though :-)
In reply to Re: find module name from the module archive
by shmem
in thread find module name from the module archive
by Lotus1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |