10

I wrote a program in Perl, and now I want to send it to buddy. I don't want him having any kind of bother with launching it.

How do I make some package which he can just click and have all things ready to launch?

PS. I can ask him to download ActivePerl and install it beforehand.

PPS. I don't need to hide .pl sources from him. I need though automatic download and install of all required CPAN modules.

Also, what if in future I will need to scale it for production delivery? Meaning, it will be not a buddy on the receiving side, but Mr. Client?

Dallaylaen
  • 5,268
  • 20
  • 34
frepkin
  • 133
  • 1
  • 8
  • Um, “click”? I’m thinking you should add some tags to your question. – tchrist Feb 13 '11 at 14:18
  • Yes, click, as in mouse-click. Could you be more specific and name some tags you mean? Well, my buddy is savvy enough with command line, so he can run install command just fine as well. – frepkin Feb 13 '11 at 15:23
  • Something like **WINDOWS**, which many of us ignore. :) Maybe also **MOUSE** or **GUI** or something. Alien world, all that. – tchrist Feb 13 '11 at 15:31
  • possible duplicate of [How can I compile my Perl script so it can be executed on systems without perl installed?](http://stackoverflow.com/questions/1237286/how-can-i-compile-my-perl-script-so-it-can-be-executed-on-systems-without-perl-in) – daxim Feb 13 '11 at 22:57
  • I put the `windows` tag because my first thought looking at the title was "through CPAN, of course". – Dallaylaen Feb 14 '11 at 08:05
  • @Dallaylaen, I want to send my program to buddy, not publish it on some network. I did mention this in my question. Also, my question isn't windows-specific and I accept linux answers too. Just it should be solution for automated one-click install. Or one-command. – frepkin Feb 14 '11 at 10:37

6 Answers6

14

I have used pp with great success. It can package a Perl interpreter and used modules all together into an executable file.

Then again there is always B::C which provides a perlcc utility, but I haven't had as much luck with that.

daxim
  • 39,270
  • 4
  • 65
  • 132
Joel Berger
  • 20,180
  • 5
  • 49
  • 104
  • Thank you, started to download it. – frepkin Feb 13 '11 at 14:43
  • 4
    PAR::Packer is excellent and probably the easiest way to go. With the Crypto filters you could even encode your source code. Although in the end if someone wants they could still decode it and reuse your code. But I don't think that's of your concern here. The only thing that _might_ cause some problems are that DLL's of some libraries won't be included when building the PAR exe. But you can include them manually. – Htbaa Feb 13 '11 at 16:07
  • 2
    `pp` generally works fine on computers without any perl. Although I've seen various problems when there was conflicts with DLLs already on the machine (program compiled from 5.8 perl runned on machine with already installed 5.10 perl and such). I've also seen many problems with Crypto filters mentioned above -- a lot programs have various versions of `libeay.dll` and it frequently caused compiled program to fail. – bvr Feb 13 '11 at 19:30
  • @daxim, I managed to install PAR::Packer, though it took me switching to `cpan` command from my usual `ppm install`, which refused to find this module. Well as I had the pp utility I went and ran it on my program. It produced 4-Mb a.exe file which seems to do nothing when launched, not even print my program's starting message. That's all success so far :( – frepkin Feb 14 '11 at 10:46
  • @frepkin, Try running it with the -x flag, this tells pp to execute the program while packing it. When it runs be sure to use any functionality that needs extra modules. When the program calls those modules, pp notices them and then is sure to include them in the package. This may be your problem. If not, you will be at the limit of my knowledge. – Joel Berger Feb 14 '11 at 13:40
  • @frepkin, I have seen that ppm didn't have PAR::Packer, so you got over that hurdle. Sorry I forgot to mention that one (I'm on Linux so I always use the cpan installer). – Joel Berger Feb 14 '11 at 13:41
  • @Joel, you respond despite I misaddressed my report, thank you. `pp -x myprogram.pl` gave me strange result: the program seems to run under `pp` normally, produces all usual output, but final .exe doesn't do or output anything, as was without `-x`. I will research this further though. – frepkin Feb 14 '11 at 14:34
  • @frepkin, my last thought would be: are you running your executable by clicking it, or at the commnd line? If you haven't been already, try it at the command line and see if there is some useful output there. Also are you using any very unusual modules? I had a little difficulty using Tk with pp, but I got it by using `-x`. – Joel Berger Feb 14 '11 at 15:47
  • 2
    @Joel, I solved the problem. Its just I was too smart and did 'modularization' of my program, with starting line being `run() unless caller;` After reading **brian d foy** 's article _How a script becomes a module_ on perlmonks and then comments I learned that PAR makes `caller` defined, so now this line looks like `run() unless caller and caller ne 'PAR';` and it works! Thank you for being online! – frepkin Feb 15 '11 at 11:31
7

For easy distribution to windows clients, its hard to beat PerlApp, Par::Packer (aka pp), or Cava Packager.

Ross Attrill
  • 2,594
  • 1
  • 22
  • 31
daotoad
  • 26,689
  • 7
  • 59
  • 100
  • Thank you @daotoad. When I run `ppm install Par::Packer` or `ppm install PAR::Packer` it says "Can't find any package that provides Par::Packer". Two other I will look into. – frepkin Feb 14 '11 at 07:54
  • 1
    If you're using ActiveState I think a ppm must be available in alternative repositories. – Htbaa Feb 14 '11 at 13:24
  • @frepkin, check out PAR::Packer on Kobesearch, it lists PPM repos that provide PPMs for different versions of ActivePerl. http://cpan.uwinnipeg.ca/search?query=PAR%3A%3APacker&mode=dist – daotoad Feb 15 '11 at 17:02
  • @Htbaa, @daotoad, I had those repositories already added to `ppm` via `ppm repo add` command, and it didn't help for some reason. But `cpan PAR::Packer` worked just fine for me. – frepkin Feb 16 '11 at 09:04
5

Although I like Joel's suggestion best I'd want to point out another solution for you. As it seems you're targeting Windows you could also use the portable version of Strawberry Perl. Install the modules you need, add your script/application to it, setup a simple batch script to launch it with the portable environment and you're set.

The biggest downside compared to the pp (PAR::Packer) solution is that the size of your application will be rather big as pp only includes that what is necessary.

Htbaa
  • 2,319
  • 18
  • 28
  • 1
    pp-generated executables are hardly svelte since "what is necessary" includes the Perl interpreter and a quite a few standard libraries before any of your script. Even a "small" pp-generated exe is several MB in size. – Michael Carman Feb 13 '11 at 21:31
  • 1
    One application we're distributed after being packed by pp is a Wx application and is about 15MB in size. When including the portable version of Strawberry Perl you include the C/C++ compiler and tool chain as well, which when zipped is almost 57MB big. So that's quite a difference. – Htbaa Feb 14 '11 at 13:23
4

You might be looking for IndigoStar's perl2exe:

Perl2Exe is a command line program for converting Perl scripts to executable files. This allows you to create stand alone programs in Perl that do not require the Perl interpreter. You can ship the executable files without having to ship your Perl source code. Perl2Exe can generate executables for Windows and Unix target hosts.

Of course, the easiest way would be if your clients could run perl.

Tim
  • 13,904
  • 10
  • 69
  • 101
  • Thank you. I will look into perl2exe. Not having to ship sources can be great, but currently I don't have the need. – frepkin Feb 13 '11 at 14:40
  • My buddy surely can download Perl itself and install it by my request, I did mention this. But I don't want having to explain him which CPAN modules he must install manually. – frepkin Feb 13 '11 at 14:49
  • perl2exe handles modules as well. – Tim Feb 13 '11 at 14:52
  • 2
    Nordendfur, Just because I'm curious (not trying to flame), what does perl2exe get you that pp does not for the money? – Joel Berger Feb 13 '11 at 15:03
  • @Joeld: Nothing significant. As far as I'm aware, pp can't make DLLs from modules to share between applications. I did upvote your answer too. – Tim Feb 13 '11 at 15:16
2

Yoy may wish to try Cava Packager. It can produce executables from Perl code on Windows, Linux and Mac OS X. It takes an alternative approach to PerlApp, pp and perl2exe. You should probably try them all and decide which you like best.

Note: As indicated by my name, I am affiliated with Cava Packager.

cavapack
  • 41
  • 1
  • 2
0

Par::Packer will do the job for you, without any fuss and is completely free. As long as you have installed the correct dependencies, you simply (on a windows machine) open a command prompt, CD into the directory where your perl source (e.g. 'samplefile.pl') resides and type: pp -o sampleprogram.exe samplefile.pl. After a minute or so, 'samplefile.exe' is compiled, and you can send it to your friend to run

Perl2Exe is a proprietary solution, and although it is good, is not free

Good luck!