📜 ⬆️ ⬇️

Perl - Deploy again

Perl - Deploy again


Perl is a scripting language, with the inability to compile into machine codes that could be directly executed on a processor. This creates an issue of deploying the application on the end user's computer. This problem is further aggravated by the presence of modules from CPAN in your application: it is sometimes problematic to make the module work on any system.

There are 3 approaches to solve this problem:

- Installing Perl on the end-user computer, installing application dependencies (usually via the installation script);
- using tools like PAR, Perl2exe, ActiveState PDK, which package the application, its modules, and the perl interpreter itself into a self-contained exe file that can be run on another machine;
- a compromise between the first two methods - using PAR to create a list of dependencies, creating a distribution kit from your application and its dependencies, which is just a folder with a script and libraries. The latter can be distributed as an archive, an installer based on, for example, NullSoft Installer.

The first method is obvious, the second is quite well written on the Internet. At the same time, both of them have drawbacks in the form of deployment complexity (the first method) and a very slow launch of the application (method 2). Both of these shortcomings made me seriously think about the third method, not well lit on the Internet.
')
As an example, create a simple GUI utility that uses Tk, so that it can work on any Windows machine and would not require a Perl installation.

1. Installing Perl on a developer machine

The best choice among distributions for Windows is Strawberry Perl , due to the fact that it comes with a C compiler that allows you to build quite a large part of CPAN modules. The recommended version is 5.16.

2. Install the necessary modules

Through the command line, run cpan and install the necessary modules. In our case, this is Tk and Par :: Packer. The Tk module is installed simply and usually without problems:

install Tk 


Unfortunately, PAR :: Packer in this version has an error due to which it is not built on most systems. Install it as follows:

 install PAR::Packer 


You will get an error like:

 windres -F pei-i386 -i winres\pp.rc -o winres\pp.res windres -o ppresource.coff winres\pp.res windres: unexpected version string length 68 != 32 + 8 dmake: Error code 129, while making 'ppresource.coff' dmake.exe: Error code 255, while making 'subdirs' RSCHUPP/PAR-Packer-1.013.tar.gz C:\strawberry\c\bin\dmake.exe -- NOT OK 


To install the module, go to the directory C: \ strawberry \ cpan \ build \, there you will see a directory like PAR-Packer-1.013-29nhQP, go to it. It contains the unpacked code of the Par :: Packer module, and now we will make corrections so that the assembly is successful. Go to the \ myldr \ winres subdirectory, open the pp.rc. file. In its original form, the file has the following contents:

 // pp.RES is created using Microsoft toolchain rc // // rc pp.rc #define PP_MANIFEST_FILEFLAGS 0 #include <windows.h> CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "pp.manifest" VS_VERSION_INFO VERSIONINFO FILEVERSION 0,0,0,0 PRODUCTVERSION 0,0,0,0 FILEFLAGSMASK VS_FFI_FILEFLAGSMASK FILEFLAGS PP_MANIFEST_FILEFLAGS FILEOS VOS_NT_WINDOWS32 FILETYPE VFT_APP FILESUBTYPE VFT2_UNKNOWN BEGIN BLOCK "StringFileInfo" BEGIN BLOCK "000004B0" BEGIN VALUE "CompanyName", " \0" VALUE "FileDescription", " \0" VALUE "FileVersion", "0.0.0.0\0" VALUE "InternalName", " \0" VALUE "LegalCopyright", " \0" VALUE "LegalTrademarks", " \0" VALUE "OriginalFilename", " \0" VALUE "ProductName", " \0" VALUE "ProductVersion", "0.0.0.0\0" END END BLOCK "VarFileInfo" BEGIN VALUE "Translation", 0x00, 0x04B0 END END WINEXE ICON pp.ico 


Delete the extra lines so that the file looks like this:

 // pp.RES is created using Microsoft toolchain rc // // rc pp.rc #define PP_MANIFEST_FILEFLAGS 0 #include <windows.h> CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "pp.manifest" 


Now go back to the PAR-Packer-1.013-29nhQP directory and execute the commands there:

 dmake dmake install 


Now the module is installed and you can proceed to creating an application distribution kit.

3. Creating an application distribution

As an example, take the following simple Hello world program.

 use Tk; use utf8; my $mw = new MainWindow; my $label = $mw -> Label(-text=>"") -> pack(); my $button = $mw -> Button(-text => "", -command => sub { exit }) -> pack(); MainLoop; 


Now we will pack the script with the dependencies:
 pp -B -p test.pl 


As a result, we get the file a.par. In fact, this is an ordinary ZIP-archive, which contains our script and dependencies. In the archive we need only the lib folder, unpack it, for example, in C: \ testapp \. There also copy our test.pl script. Now you need to copy the perl interpreter and the dll needed to run it into this folder. To do this, copy the following files from the C: \ strawberry \ perl \ bin directory:

libgcc_s_sjlj-1.dll
libstdc ++ - 6.dll
perl.exe
perl516.dll

As a result, you need to get the following directory:
 12.08.2012 23:06 <DIR> lib 11.04.2012 19:23 96 256 libgcc_s_sjlj-1.dll 11.04.2012 19:23 829 440 libstdc++-6.dll 09.08.2012 10:04 16 384 perl.exe 09.08.2012 10:04 16 384 wperl.exe 09.08.2012 10:04 1 458 176 perl516.dll 12.08.2012 23:05 256 test.pl 


Only the final touch remains - you need to add the PAR module itself to the distribution, since the pp utility does not take the PAR module into account when compiling the dependency list. To do this, copy the following objects from the C: \ strawberry \ perl \ vendor \ lib directory to the C: \ testapp \ lib directory:

 12.08.2012 19:57 <DIR> PAR 02.12.2011 14:15 39 863 PAR.pm 


Now you have a ready-to-launch application in the C: \ testapp \ directory. For the purity of the experiment, to be sure that the strawberry perl installed on the machine and its libraries will not be able to participate in the launch of our application. To do this, rename the directory C: \ strawberry to C: \ strawberry_hide. Now you can go to the C: \ testapp directory and start the application using the command:

 perl test.pl 


4. Results

We got a directory with our application, which can be transferred to any other system using a simple copy. If you wish, you can create an installer, or distribute the application in the archive. Remote execution from a folder shared via Netbios is not recommended - very low download speed.

To make your application run comfortably, create a shortcut for perl.exe (or wperl.exe if you do not want the console window to appear at startup) with the parameter in the form of your script. Now it remains only to make a shortcut on the desktop, and the program is ready for use.

Source: https://habr.com/ru/post/149586/


All Articles