in reply to How can I catch a failure of use?

Hi

just recently there was a blog entry of NEILB who published his new module Module::Loader. In this blog he linked to a comparison he did before comparing several CPAN modules helping to load modules dynamically.

This comparison http://neilb.org/reviews/module-loading.html is probably worth a look for finding the best solution for your plugin/fallback kind use case.

Regards
McA

Replies are listed 'Best First'.
Re^2: How can I catch a failure of use?
by syphilis (Archbishop) on Oct 14, 2014 at 12:00 UTC

    With (eg) Devel::Peek I can do:
    C:\>perl -MDevel::Peek -le "Dump 2;" SV = IV(0x1d7f9e8) at 0x1d7f9ec REFCNT = 1 FLAGS = (PADTMP,IOK,READONLY,pIOK) IV = 2
    Is there any way that Module::Load (or any other method of runtime loading) can load Devel::Peek such that "Dump 2;" (no parentheses) will work ?
    C:\>perl -le "require Devel::Peek; Devel::Peek->import('Dump'); Dump 2 +;" Number found where operator expected at -e line 1, near "Dump 2" (Do you need to predeclare Dump?) syntax error at -e line 1, near "Dump 2" Execution of -e aborted due to compilation errors. C:\>perl -MModule::Load -le "load 'Devel::Peek'; Devel::Peek->import(' +Dump'); Dump 2;" Number found where operator expected at -e line 1, near "Dump 2" (Do you need to predeclare Dump?) syntax error at -e line 1, near "Dump 2" Execution of -e aborted due to compilation errors.
    (I'm not the OP, btw - just wondering ...)

    Cheers,
    Rob

      Hi,

      you just have to mimic what Perl does itself:

      perl -le "BEGIN { require Devel::Peek; Devel::Peek->import('Dump') } D +ump 2"

      Regards
      McA

        you just have to mimic what Perl does itself

        Yes, I think this is the solution that the OP needs.

        However, it's not really relevant to my question about *runtime* loading as anything that happens in a BEGIN{} block happens at *compile-time*.
        (I'm thinking it's not possible to avoid the parentheses if a module is loaded at runtime.)

        Cheers,
        Rob