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


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

Replies are listed 'Best First'.
Re^3: How can I catch a failure of use?
by McA (Priest) on Oct 14, 2014 at 13:42 UTC

    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