Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Conditionally faking a module

by bobf (Monsignor)
on Jan 13, 2010 at 18:40 UTC ( #817255=note: print w/ replies, xml ) Need Help??


in reply to Conditionally faking a module

If you want to run some code if a module isn't installed, just test the use statement for failure:

eval "use Cava::Pack" or do { # your code goes here };

Super Search will find several threads on this topic, including Auto install of a perl package if 'use' statement fails.


Comment on Re: Conditionally faking a module
Select or Download Code
Replies are listed 'Best First'.
Re^2: Conditionally faking a module
by wanna_code_perl (Pilgrim) on Jan 13, 2010 at 19:01 UTC

    Unfortunately, your example doesn't work:

    eval "use Cava::Pack" or do { die "Using faked out Cava::Pack\n"; }

    I see the "Using faked out Cava::Pack" message on both Linux and Win32 (where Cava::Pack is indeed available).

      That is the reason for a true value, 1
      eval "use Cava::Pack; 1" or die "Oh noes! $@"; eval "use HOW::Cava::Pack; 1" or die "HOW!?! $@"; __END__ HOW!?! Can't locate HOW/Cava/Pack.pm in @INC (@INC contains: C:/perl/5 +.10.1/lib/MSWin32-x86-multi-thread C:/perl/5.10.1/lib C:/perl/site/5. +10.1/lib/MSWin32-x86-multi-thread C:/perl/site/5.10.1/lib .) at (eval + 2) line 1. BEGIN failed--compilation aborted at (eval 2) line 1.
      Hmm, I don't recall installing Cava::Pack :)

      The code being executed by eval ("") returns nothing (()), which is indistinguishable from the value eval returns on failure.

      You need

      eval "use Cava::Pack; 1"

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://817255]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (13)
As of 2015-07-30 11:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (271 votes), past polls