How to test if a module is installed ?

2002-04-19 Thread Dennis Senftleben

Hi !
My perlscript uses the Image::Size module.
It works fine if it is installed, but if not I get a compilation error msg.
How can I test with perl if it is installed on my system ?
Is there something like 
if ( -e Image::Size ) { use Image::Size ;}
else { print(" module not installed");}

Dennis


icq: #28395132

---
This message was sent by Postaci Webmail. See www.trlinux.com for details.


RE: How to test if a module is installed ?

2002-04-19 Thread Nikola Janceski

command line:
perl -e "use Image::Size"

if you get an error, it's missing, else it's installed.

> -Original Message-
> From: Dennis Senftleben [mailto:[EMAIL PROTECTED]]
> Sent: Friday, April 19, 2002 12:03 PM
> To: [EMAIL PROTECTED]
> Subject: How to test if a module is installed ?
> 
> 
> Hi !
> My perlscript uses the Image::Size module.
> It works fine if it is installed, but if not I get a 
> compilation error msg.
> How can I test with perl if it is installed on my system ?
> Is there something like 
> if ( -e Image::Size ) { use Image::Size ;}
>   else { print(" module not installed");}
> 
> Dennis
> 
> 
> icq: #28395132
> 
> ---
> This message was sent by Postaci Webmail. See www.trlinux.com 
> for details.
> 



The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: How to test if a module is installed ?

2002-04-19 Thread Hanson, Robert

Something like this should work...

if ( eval "require Image::Size" ) {
Image::Size->import();
print "The module is installed!";
}
else {
print "It's not installed!";
}

Rob

-Original Message-
From: Dennis Senftleben [mailto:[EMAIL PROTECTED]]
Sent: Friday, April 19, 2002 12:03 PM
To: [EMAIL PROTECTED]
Subject: How to test if a module is installed ?


Hi !
My perlscript uses the Image::Size module.
It works fine if it is installed, but if not I get a compilation error msg.
How can I test with perl if it is installed on my system ?
Is there something like 
if ( -e Image::Size ) { use Image::Size ;}
else { print(" module not installed");}

Dennis


icq: #28395132

---
This message was sent by Postaci Webmail. See www.trlinux.com for details.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: How to test if a module is installed ?

2002-04-19 Thread Michael Lamertz

On Fri, Apr 19, 2002 at 06:02:32PM +0200, Dennis Senftleben wrote:
> Hi !
> My perlscript uses the Image::Size module.
> It works fine if it is installed, but if not I get a compilation error msg.
> How can I test with perl if it is installed on my system ?
> Is there something like 
> if ( -e Image::Size ) { use Image::Size ;}
>   else { print(" module not installed");}

Although two other people already have answered, I think I can add a bit
more information:

First of all: In your case, it seems as if the application should behave
as it already does:  'die' if not all requirements are fulfilled.

If, however, you want to run anyways, but with limited features, first
let's look into the documentation:

perldoc -f use

gives us:

-- snip --
use Module VERSION LIST
use Module VERSION
use Module LIST
use Module
use VERSION
Imports some semantics into the current package
from the named module, generally by aliasing cer-
tain subroutine or variable names into your pack-
age.  It is exactly equivalent to

BEGIN { require Module; import Module LIST; }

except that Module must be a bareword.
-- snip --

So what you can do is this:

-- snip --
#!/usr/bin/perl

use warnings;
use strict;

BEGIN {
eval { require Data::Dumper; import Data::Dumper; };
eval { require funky_named_mod; import funky_named_mod; };
}

print Dumper({a => 1, b => 2, c => 3})
if $INC{'Data/Dumper.pm'};
print Unavailable_function()
if $INC{'funky_named_mod.pm'};
-- snip --

Now you can decide what to do at runtime.  Stuff the parts that are
dependand on Module_X into a clause checking %INC for the corresponding
key 'Module_X.pm';

Search for '%INC' in

perldoc perlvar

-- 
   If we fail, we will lose the war.

Michael Lamertz|  +49 221 445420 / +49 171 6900 310
Nordstr. 49|   [EMAIL PROTECTED]
50733 Cologne  | http://www.lamertz.net
Germany|   http://www.perl-ronin.de 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]