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

I was experimenting today with making executable files out of Perl scripts.

I post regularly on boards and the members wanted a way to download and archive the contents.

I've inherited a useful script, which is barely twenty lines, but it requires LWP::userAgent.

A lot of people would like to be able to use this script without having to install Perl.

There's a company that makes a thing called "Perl2EXE" which can make any script into a Windows executable. I did a version of it using that, which was not small, but worked. (It's demo-only ware, and I haven't paid up, but this is just an experiment)

Then I tried to come up with a Mac version. There's such a thing as a runtime file which can be saved from a MacPerl script, but when I tried, the one line "use LWP::UserAgent;" sent me off on a chase through about twenty different modules.

You can't use LWP::UserAgent without various parts of HTTP:: and HTML:: and Exporter.pm and about fifty other things. By the time I'd ferreted through the modules I'd need to include in a special "lib" directory, it would have been easier to just say "Download MacPerl", come back, then run this script.

So do I have a question? Maybe it's

  1. There must be something very smart about the Perl2EXE software if it can find all the modules and all the modules that the modules call on and the modules that they call on in turn -- is there anything like that freely available? And does Perl2EXE somehow compile them into binaries, rather than including them wholesale?

  2. Did the modules that I needed to use for my simple hit-on-a-page, munge-the-source script really need every line of those modules, or was it just a cascade of "require" statements? Could I have got away with just 10% of HTTP::Whatever and less than half of CGI::SomethingElse, if I'd had an even smarter tool to grab only the parts I'd really needed?

--
Weaselling out of things is important. It's what separates us from the animals ... except the weasel.

Replies are listed 'Best First'.
Re: Perl Executables
by peschkaj (Pilgrim) on Feb 01, 2002 at 12:53 UTC
    The modules may not have been entirely needed. One of the things that I have been forced by necessity to do is tell Perl exactly which functionality I need from each module. Now, this isn't all that easy to do with dependencies, but it beats loading the entire POSIX module into the EXE.

    As best as I can understand it, when you execute a perl script, or compile it to byte code, the engine pulls in all of the modules that are declared. If you don't want to pull them all in, you need to use something like: use POSIX qw(:errno_h); That *should* fix the problem you have of the executables being large. Hopefully someone else will have better input than I do. :)
      Correct me if I'm wrong (this happens frequently), but doesn't the use MODULE qw(:method) only work if the module exports the method? I've tried to limit my .exe's before, be it only works on certain methods in certain modules.

      And, I've not used Perl2exe as extensively as I've used ActiveState's PerlSvc and PerlApp (from Perl Dev Kit). Limiting the imported methods does not help as the modules are typically included as .dll's. So, while I might only use two methods from Win32::Process, it includes the entire Win32/Process/Process.dll. There is an option to exclude the .dll's from the compile, thus making the .exe smaller, but the .dll's must be installed on the target machine to do so. You might look for similar functionality in Perl2exe.

Re: Perl Executables
by peschkaj (Pilgrim) on Feb 01, 2002 at 15:53 UTC
    I'm not too sure. Almost all of my perl coding experience has been on *nix boxes (FreeBSD, Slackware, and HP-UX), so I couldn't tell you much about the win32 implementation.
Re: Perl Executables
by axelrose (Scribe) on Feb 01, 2002 at 21:41 UTC
    There are some standalone build scripts available for MacPerl. I've build my own which runs perfectly on a large number of my company's Macs (no MacOS X).
    The idea is to recursively check for use/require lines. Quite a few tweaks take care for "require $module" and similar lines. Therefore it can never be perfect and I hesitate to publish this to a broader audience.
    I was successful though to build a standalone application for "amphetadesk" (www.disobey.com/amphetadesk/), a rather large application.

    I suggest I'll send the code to you by email (I tried /msg Cody_Pendant)
      Thanks for your help, all of you.

      Axel, I've come across your posts in various online places and I downloaded a couple of different builds of your "standalone-builder" scripts, but I got memory errors when I tried to use them.

      By all means email me: hostile17@bigfoot.com with some code, or better, if it's a big file, a link to somewhere I can download it.

      I'll also be checking out the other solutions.

      Perl2EXE, by the way, does indeed have options to include all necessary modules in the package, or have them as a separate DLL file. While this might seem illogical at first glance, (you can have a megabyte of code either in 1x1MB files or in 2 half-megabyte files?) I guess if you wrote ten successive versions, or you wrote ten different programs, all of which required nothing but LWP::UserAgent to run, it would make sense for the module code to be a one-time thing.

      --
      Weaselling out of things is important. It's what separates us from the animals ... except the weasel.