Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

LWP vs ExtUtils::Installed vs libwww::perl vs Module::Metadata

by Anonymous Monk
on Sep 23, 2018 at 06:56 UTC ( [id://1222878]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

perl -MExtUtils::Installed -le 'print join "\n", grep /lwp/i, ExtUtils +::Installed->modules()' LWP::ConsoleLogger LWP::MediaTypes LWP::Protocol::http::SocketUnixAlt LWP::Protocol::https Test::LWP::UserAgent perl -MExtUtils::Installed -le 'print join "\n", grep /libwww/i, ExtUt +ils::Installed->modules()' libwww::perl perl -MExtUtils::Installed -le 'print join "\n", ExtUtils::Installed-> +files("libwww::perl")' /perl-5.26.2/lib/site_perl/5.26.2/LWP.pm 43 more files... perl -MModule::Metadata -MData::Dumper -le' print(Dumper(Module::Metad +ata->new_from_module("libwww::perl")))' $VAR1 = undef; perl -MModule::Metadata -MData::Dumper -le' print(Dumper(Module::Metad +ata->new_from_module("LWP")))' $VAR1 = bless( { 'filename' => '/perl-5.26.2/lib/site_perl/5.26.2/LWP. +pm', 'module' => 'LWP', perl -MExtUtils::Installed -le 'print join "\n", ExtUtils::Installed-> +files("LWP")' LWP is not installed at -e line 1.

Replies are listed 'Best First'.
Re: LWP vs ExtUtils::Installed vs libwww::perl vs Module::Metadata
by haukex (Archbishop) on Sep 23, 2018 at 07:52 UTC

    Note that libwww::perl is not the name of a module, there is no libwww/perl.pm - the distribution is libwww-perl. So I'm not surprised that Module::Metadata is saying that there is no module libwww::perl. It is strange, however, that ExtUtils::Installed is reporting libwww::perl but not finding LWP.pm. Its documentation says "It uses the information stored in .packlist files created during installation to provide this information", and there is a file auto/libwww/perl/.packlist - I'm not sure why it isn't looking at the contents of that file like its documentation describes, which does list LWP.pm (and I don't have too much time right now to dig into the source to see if it's some kind of bug*).

    Personally, if I need a core module to check if some module is installed, I like to use check_install from Module::Load::Conditional, although that doesn't handle distribution names like libwww-perl either. You haven't said if/why you need this?

    * Update: See my post here, looks like a bug to me.

      > You haven't said if/why you need this?

      I'm analyzing Perl and have discovered 4 distributions out of about 1000 CPAN installations where ExtUtils::Installed and Module::Metadata don't agree:

      1. LWP (or libwww::perl) 1222878
      2. MIDI (or MIDI-Perl) 1222886
      3. Astro (Namespace appears as a module to ExtUtils::Installed->modules())
      4. Role::Identifiable (doesn't really exist)

      
      perl -MExtUtils::Installed -le 'print join "\n", grep /astro/i, ExtUtils::Installed->modules()'
      
      Astro
      Astro::Constants
      Astro::Coord::ECI
      Astro::Coords
      Astro::FITS::Header
      Astro::MapProjection
      Astro::MoonPhase
      Astro::PAL
      Astro::Sunrise
      Astro::Telescope
      Astro::Time::HJD
      Astro::Units
      Astro::WaveBand
      DateTime::Astro
      
      perl -MExtUtils::Installed -le 'print join "\n", ExtUtils::Installed->files("Astro")'
      
      /perl-5.26.2/lib/site_perl/5.26.2/Astro/Coord.pm
      /perl-5.26.2/lib/site_perl/5.26.2/Astro/Misc.pm
      /perl-5.26.2/man/man3/Astro::Time.3
      /perl-5.26.2/lib/site_perl/5.26.2/Astro/Time.pm
      /perl-5.26.2/man/man3/Astro::Coord.3
      /perl-5.26.2/man/man3/Astro::Misc.3
      
      perl -MModule::Metadata -MData::Dumper -le 'print(Dumper(Module::Metadata->new_from_module("Astro")))'
      
      $VAR1 = undef;
      
      
      Finally:
      
      perl -MExtUtils::Installed -le 'print join "\n", grep /identifiable/i, ExtUtils::Installed->modules()'
      
      Role::Identifiable
      
      perl -MExtUtils::Installed -le 'print join "\n", ExtUtils::Installed->files("Role::Identifiable")'
      
      /perl-5.26.2/man/man3/Role::Identifiable::HasIdent.3
      /perl-5.26.2/lib/site_perl/5.26.2/Role/Identifiable/HasTags.pm
      /perl-5.26.2/lib/site_perl/5.26.2/Role/Identifiable/HasIdent.pm
      /perl-5.26.2/man/man3/Role::Identifiable::HasTags.3
      
      perl -MModule::Metadata -MData::Dumper -le 'print(Dumper(Module::Metadata->new_from_module("Role::Identifiable")))'
      
      $VAR1 = undef;
      
      
        I'm analyzing Perl

        Could you be more specific? Are you hunting bugs in ExtUtils::Installed? Because that's what this issue feels like to me at the moment, although I still don't have enough time to investigate in detail.*

        If you're not hunting bugs, perhaps you could explain what exactly you've analyzing and why, then we could probably suggest more fitting tools. If I guess you might be trying to figure out which modules are installed and which files belong to which distributions, then why not just use one reliable tool (maybe that's Module::Metadata?) instead of trying two?

        You also haven't said if you need to figure out distribution names as well; in this node there appears to still be a mixup of distribution names (MIDI-Perl) with actual modules (MIDI/MIDI.pm).

        * Update: See my post here, looks like a bug to me.

      Some ?most distros for decade+ remove packlist files so instmodsh can't do its job.. A humble tool it was long ago
Re: LWP vs ExtUtils::Installed vs libwww::perl vs Module::Metadata
by haukex (Archbishop) on Sep 24, 2018 at 14:14 UTC

    I took a quick look at the source, this code is what is responsible for incorrectly turning auto/libwww/perl/.packlist into libwww/perl.pm. Personally I'd consider this a bug, or at least a "limitation" that occurrs when the location of the .packlist file(s) don't match the module names (but rather the distribution names). This appears to be true of the four modules named in this node, and if one were to analyze the other ~38k CPAN distros, I'm sure there's more out there.

      I was hoping someone with more perl wisdom would know where to look and what to look for. Thank you haukex! ExtUtils::Installed->modules() outputs module names (and apparently the occasional dist, oops) and Module::Metadata reads module names or files (but not dists). These core modules are very reliable and designed to work together. Anyway when ExtUtils::Installed->modules() sends a dist name to Module::Metadata->new_from_module() and the lookup fails, the solution is to send that dist name back to ExtUtils::Installed->files() to get a list of the module files, which Module::Metadata->new_from_file() understands. Thank you for helping me realize what's happening and fix a very old and annoying bug (in my code).
Re: LWP vs ExtUtils::Installed vs libwww::perl vs Module::Metadata
by Anonymous Monk on Sep 23, 2018 at 09:31 UTC
    Here's another mystery:
    perl -MExtUtils::Installed -le 'print join "\n", grep /midi/i, ExtUtils::Installed->modules()'
    
    MIDI-Perl
    MIDI::Ngram
    MIDI::Pitch
    MIDI::Praxis::Variation
    MIDI::Simple::Drummer
    MIDI::Tab
    MIDI::Trans
    
    perl -MExtUtils::Installed -le 'print join "\n", ExtUtils::Installed->files("MIDI-Perl")'
    
    /perl-5.26.2/lib/site_perl/5.26.2/MIDI.pm
    13 more files...
    
    perl -MModule::Metadata -MData::Dumper -le 'print(Dumper(Module::Metadata->new_from_module("MIDI-Perl")))'
    
    $VAR1 = undef;
    
    perl -MModule::Metadata -MData::Dumper -le 'print(Dumper(Module::Metadata->new_from_module("MIDI")))'
    
    $VAR1 = bless( {
                     'module' => 'MIDI',
                     'filename' => '/perl-5.26.2/lib/site_perl/5.26.2/MIDI.pm',
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1222878]
Approved by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-18 17:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found