Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Loading Local Modules

by CodeJunkie (Monk)
on Sep 10, 2003 at 10:15 UTC ( #290357=perlquestion: print w/replies, xml ) Need Help??

CodeJunkie has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,
I'm looking for some advice. I have written a web app and slightly niavely used a non-standard Perl module namely XML::Simple. Now every time I sell this software to a company I have to get them to install this module and not all hosting companies are happy doing this. Therefore I am making life difficult for myself. I wish I hadn't used the module now, I was really just trying to be clever. I could have written the code another way, but chose XML simple because I thought it would be cool.

So I think the moral of this story is DON'T USE NON-STANDARD PERL MODULES!

I'm trying to think of ways around this predicament without re-writting my code, I thought about using the

use lib '/export/home/whatever/lib/';

Setting a local lib directory and installing the module locally. This works, until I try and run it, in which case it starts to ask for more and more modules, such as Then it just complains because the versions are all wrong.

So can anyone give me any advice about this, what should I do? Maybe it would be simplier to use another module rather than XML::Simple, does anyone know of very similar but standard XML modules that I could use instead of this?

Your help is as always really appreciated.


Replies are listed 'Best First'.
Re: Loading Local Modules
by Joost (Canon) on Sep 10, 2003 at 11:03 UTC
    You COULD try to install the module locally (in a specific directory) using a fresh perl install:

    perl Makefile.PL LIB=/used/perl/modules/for/project make && make test && make install
    The bundle the /used/perl/modules/for/project directory with you distribution and use lib for that directory. This might create unportable distributions for perl-only modules, and it certainly will create unportable distributions for modules build in XS, so watch out.

    XML::Simple, by the way, uses XML::Parser, which uses the C expat library, which is not standard for most systems. You'll need to get the perl version, OS version, probably the C compiler, and all library versions correct if you want to copy the result of an install of XML::Simple to other machines. You might then even be able to use PAR to make the distribution. But probably not.

    In short: installing != copying .pm files. That's why this whole Makefile.PL -> make -> make test -> make install thing is there in the first place.

    For the XML modules, I think they are way too useful not to be installed anyway. Any decent hosting company should know that. Tell your clients their hosting company sucks. It won't help, but it might make you feel better :-)

    -- #!/usr/bin/perl -w use strict;$;= ";Jtunsitr pa;ngo;t1h\$e;r. )p.e(r;ls ;h;a;c.k^e;rs ";$_=$;;do{$..=chop}while(chop);$_=$;;eval$.;

      Thanks for the advice Joost, really helpful. I always wondered what all that makefile business was about :-)

      I think i'll just opt for slagging off the web hosts that don't have it installed and refuse to do so... and perhaps think about writing a version that doesn't use XML, was a bit over the top for my purpose anyway! :-)


Re: Loading Local Modules
by barbie (Deacon) on Sep 10, 2003 at 11:38 UTC
    As Joost has mentioned, you do have the option of PAR. This has been a godsend to me for transporting modules across Win32 boxes.

    Depending upon your requirements, you can wrap what you need up in two ways.

    Firstly as a PAR file containing the rogue module and all it's dependancies. Using pp (the Perl Packager) you can have:

    pp -M XML::Simple -p xmlsimple

    Alternative you can create a specific PAR file, but this will require you to delve into Module::ScanDeps a little and write a script like one I've recently written that can tar (Archive::Tar) or zip (Archive::Zip) the appropriate contents. Having created your PAR file you simple access it in your code as:

    use PAR 'xmlsimple.par';

    Secondly as an EXE file that runs as if you'd called your main script. Again using pp:

    pp -o myscript.exe
    which will wrap up the script with all it's dependancies and allow you to deploy as if a single script.

    PAR and it's additional scripts are one of the most useful bundles you'll find on CPAN, when it comes to deploying your Perl applications.

    Barbie | Birmingham Perl Mongers |

Re: Loading Local Modules
by Abigail-II (Bishop) on Sep 10, 2003 at 10:33 UTC
    So can anyone give me any advice about this, what should I do?

    Assuming XML::Simple has an open source license that allows it to be freely distributed (which, if XML::Simple is on CPAN, it most likely has), simple distribute XML::Simple with your product.


      Yeah this is what i've tried to do, but it then seems to ask for because it obvioyusly uses it. So I installed that as well, then it complained about some problem with XML::Parser::Expat, so I installed that as well. Then it complained about.

      Can't locate object method "bootstrap" via package "XML::Parser::Expat +" at lib/XML/Parser/ line 29

      So I started to wonder if this would ever end...


        Did you read the README for XML::Parser? You have to install expat. An alternative is to install XML::SAX, which will install XML::SAX::PurePerl, which will be used by XML::Simple. This way you don't have to install an external library.

        You should also install CPANPLUS, that will make installing modules easier (although it will not solve the fact that you have to install expat separately in this case).

        CPANPLUS will also let you write a bundle file for your configuration, or just let you automagically install the needed modules, see Perl Module administration with CPANPLUS.

        Don't give up, it might be a pain in the short term, but eventually it will save you tons of time, as you will then be able to use all of CPAN and not just the very limited subset included in the core.

Re: Loading Local Modules
by guha (Priest) on Sep 10, 2003 at 10:25 UTC

    Just a hunch, could you not unshift @INC with the desired path, where you install all the relevant modules, matching versions and all

    You might need to do this in a BEGIN block or at least before use-ing the modules


      Just a hunch, could you not unshift @INC

      How is the trivial difference between this and use lib; supposed to address the OP's problem?

      From perldoc lib:

                 use lib LIST;
             is almost the same as saying
                 BEGIN { unshift(@INC, LIST) }
             For each directory in LIST (called $dir here) the lib module also
             checks to see if a directory called $dir/$archname/auto exists.  If so
             the $dir/$archname directory is assumed to be a corresponding architec-
             ture specific directory and is added to @INC in front of $dir.

      --Bob Niederman,

      All code given here is UNTESTED unless otherwise stated.

Re: Loading Local Modules
by coreolyn (Parson) on Sep 10, 2003 at 20:31 UTC

    Until recently (see expat library issue) I've had success using modules from non-standard locations by adding to @INC the PERL5LIB environment variable and the LD_LIBRARY_PATH Module.

    Admittedly my process is very manual intensive; building in the standard location then moving as required, but I have achieved the desired result

Re: Loading Local Modules
by DrHyde (Prior) on Sep 10, 2003 at 18:50 UTC
    Nah, the moral of the story is don't use that XML junk :-) Every time I've had to it has caused pain, and that's even when I *can* install modules to my heart's content on machines I control.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://290357]
Approved by broquaint
Front-paged by broquaint
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2020-06-02 14:35 GMT
Find Nodes?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?

    Results (18 votes). Check out past polls.