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 :-)

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

In reply to Re: find module name from the module archive by shmem
in thread find module name from the module archive by Lotus1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.