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]

Reply via email to