Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Perl Monk, Perl Meditation
 
PerlMonks  

Including Modules with a script

by Mandor (Pilgrim)
on Jul 11, 2001 at 12:07 UTC ( [id://95646]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

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

I want to include some modules with a small script which I've done.
It reads a certain XML file on the net which contains server status
reports and prints out niceley formatted HTML. I've decided that I am
going release it to the public if the script comes out nice.
Now two questions arrise since I want to include not-so-common Modules with the script
(UBB has MIME:Lite included for example) in case the webmaster can't install Modules himself.

1) Is it perfectly legal to include these Modules with the script (since they can be found on CPAN)?
2) I thought of including a Modules subdirectory (with furher subdirectories) with the script. As you can see in my code example I
use FindBin to get the path of the script and then load the Modules from the subdirectory. While this
works fine I get an "Undefined subroutine &main::get called at script.pl" error.
When I replace the my $tree     = get ($xml_path);with my $tree     = LWP::Simple -> get ($xml_path);
that works but replacing it like this doesn't work for the XML::Simple modules because I get a
"Can't use string ("XML::Simple") as a HASH ref while "strict refs" in use at Modules/XML/Simple.pm 494" error".
What can be done to overcome this problem? Or do I have to use a different XML parser?
#!/usr/local/bin/perl use strict; use FindBin qw($Bin); use lib "$Bin" . "/Modules"; use Modules::LWP::Simple; use Modules::XML::Simple; use Modules::HTML::Template; sub generate_reports { my $xmlfile = get ($xml_path); my $tree = XMLin ($xmlfile); ... }

Replies are listed 'Best First'.
Re: Including Modules with a script
by davorg (Chancellor) on Jul 11, 2001 at 12:16 UTC

    I think that your best bet is to take the easiest route. That is to list the required modules in a README file and tell users that they need to install the modules from CPAN before installing your application.

    --
    <http://www.dave.org.uk>

    Perl Training in the UK <http://www.iterative-software.com>

Re: Including Modules with a script
by TheoPetersen (Priest) on Jul 11, 2001 at 12:19 UTC
    1) It's legal to distribute modules that are GPL and/or Artistic, as long as you abide by their licenses. You should check the license of each module.

    2) Your Modules namespace is causing problems. While 'use Modules::LWP::Simple' may work without an error, the loaded module undoubtedly identifies a different package:

    package LWP::Simple;
    That may be causing your problem with XML::Simple, though I haven't tried it to see.

    It would be better to instruct the user to drop the extra modules in a directory of their choice and modify the 'use lib' line at the top of your script to refer to it. Besides, the user may be just fine with CPAN and already have the modules installed.

Re: Including Modules with a script
by bikeNomad (Priest) on Jul 11, 2001 at 13:33 UTC
    Note that it's simple to install CPAN modules, assuming that CPAN has been set up on the machines in question (configured for ftp paths, etc.). From the CPAN manpage:

    use CPAN; # install my favorite programs if necessary: for $mod (qw(Net::FTP MD5 Data::Dumper)){ my $obj = CPAN::Shell->expand('Module',$mod); $obj->install; }
Re: Including Modules with a script
by Abigail (Deacon) on Jul 11, 2001 at 13:49 UTC
    The answer to point 1) is no. Just the existance of a Module on CPAN doesn't give you the right to distribute it in they way you suggest. Many modules on CPAN will allow you to redistribute them (but be aware of modules that are GPL only, if your program isn't GPLed, it could be that you cannot include the module in your program the way you propose), but that is not implied by the module being present on CPAN. All that is implied is that you can distribute the module as it is found on CPAN, which will often be a tarball suitable for the perl Makefile.pl; make; make test; make install; route.

    As for point 2), I would really loathe authors that put Modules in (a subdirectory of) the directory executables are found. Modules are modules, and should go into a module directory, so they can be shared with other programs that do play the game as it should be played. If you think there are admins out there who cannot install modules, the proper way is to write a document explaining how to install modules instead of making a mess of some systems. Besides, you like your programs to be used, don't you? Make a mess and garanteed, admins all over the world toss your code from their systems as fast as they installed it, and ban anymore code from the same author.

    -- Abigail

Re: Including Modules with a script
by Mandor (Pilgrim) on Jul 11, 2001 at 20:02 UTC
    Thanks for your suggestions, folks.
    Okay it works with package command just as TheoPetersen said. So special thanks to you

    So now to the aspect of why to do it at all.
    Many people have ISPs which are cheap but almost
    certainly won't install new modules for their customers
    (Or it just takes too long).
    I think that's why UBB includes some modules with their program.
    Also it's convenient not to have to ask your
    sysadmin before you can use a script. I think that's a valid point.
    As much as I love "clean" installations you can think of cases where it's
    easier/faster just to include a module with a program (as long it's legally all right).

    For example :
    I wanted to test my script on an UNIX machine (I'm on Win32).
    So I uploaded it to my ISP (who hasn't got HTML::Template or XML::Simple installed).
    I know that my ISP would install new modules for me but by including these modules it was a little easier
    for me and only took some minutes.

    As I am not too much into UNIX I am not aware if there
    might be technical difficulties arrising from doing this but I would be interested in hearing about that if this is the case.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://95646]
Approved by root
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.