Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • You really like to goad me to put my "evil hat" on. This is a crude example to show the concept -- it would need to be a bit more helpful and a bit more robust for real use.

    package Nice;
    use strict;
    use warnings;
    no warnings 'once';

    *CORE::GLOBAL::require = sub {
      my $mod = shift;
      eval { CORE::require($mod) };
      if ($@) {
        if ( my ($mod) = $@ =~ /\ACan't locate (\S+)/ ) {
          $mod =~ s{/}{::}g;
          $mod =~ s{\.pm$}{};
          $@ = <<"END";
    Can't locate $mod in your Perl library.  You may need to install it
    from CPAN or another repository.  Your library paths are:
    END
          $@ .= "  $_\n" for @INC;
        }
        die $@;
      }
      return 1;
    };

    1;

    Here's an example:

    $ perl -MNice -MFoo::Bar -e 1
    Can't locate Foo::Bar in your Perl library.  You may need to install it
    from CPAN or another repository.  Your library paths are:
      /opt/perl/5.10.1/lib/5.10.1/x86_64-linux-ld
      /opt/perl/5.10.1/lib/5.10.1
      /opt/perl/5.10.1/lib/site_perl/5.10.1/x86_64-linux-ld
      /opt/perl/5.10.1/lib/site_perl/5.10.1
      .

    Could be done via PERL5OPT or perhaps the site-customization file.

    -- dagolden [dagolden.com]

    • Also, maybe try to trap the file and line number where they tried to require the module?

    • Nice first hack though. Seriously.

    • It'd be nice if Padre detected this in its console output too - and automatically opened a CPAN GUI to help the user install the dependency (http://padre.perlide.org/trac/ticket/70#comment:2)