develooper Front page | perl.par | Postings from March 2012

Complete Solution - Packing multiple scripts in a standalone executablewith pp

Thread Previous
From:
Dirk Joos
Date:
March 15, 2012 01:25
Subject:
Complete Solution - Packing multiple scripts in a standalone executablewith pp
Message ID:
4F6114C3.3060501@dirkundsari.de
Hello,

now I have the complete solution.

1.) pp -p -o packed_script.par main_script.pl helper_script.pl
2.) add the file "main.pl" to "packed_script.par" in the /script folder 
where now also are "main_script.pl" and "helper_script.pl"

main.pl

if (defined $ENV{PAR_APP_REUSE}) {
     my $filename = $ENV{PAR_APP_REUSE};
     delete $ENV{PAR_APP_REUSE};
     $ENV{PAR_0} = $filename;

     PAR::_run_external_file($filename, 1);
     exit();
}


my $zip = $PAR::LibCache{$ENV{PAR_PROGNAME}} || Archive::Zip->new(__FILE__);
my $member = eval { $zip->memberNamed('script/main_script.pl') }
         or die qq(main.pl: Can't open perl script 
"script/main_script.pl": No such file or directory ($zip));



PAR::_run_member($member, 1);

3.) pp -o  packed_script --reusable packed_script.par

Here how to call the external helper script from the main script:

#############################################################
# part in the main_script.pl where the helper script is invoked
#############################################################

my $cmd;
if( defined $ENV{PAR_TEMP} )
{
     $cmd = "$0 --par-options --reuse 
$ENV{PAR_TEMP}/inc/script/helper_script.pl";
}
else
{
     $cmd = "perl helper_script.pl";
}

Now the main script and another external script "helper_script.pl" are 
packed in one standalone executable. It is running without the need of a 
perl installation. And all needed modules are also packed.

The solution is complete and I'm happy that I can now pack multiple 
scripts into one standalone executable with pp.

Because several steps are needed to achieve this solution, it would be 
great when pp would get another option (e.g. --main_script). So pp knows 
what is the main script and what are the helper scripts. This would have 
the advantage that it is not necessary to add a "main.pl" manually and 
so the step of creating a par would not be necessary.

Example: pp -o packed_script --reusable --main_script main_script.pl 
helper_script.pl

Feedback is welcome.

Cheers,
Dirk


Am 14.03.2012 22:18, schrieb Dirk Joos:
> Hello,
>
> I have most part of the solution. The --reusable option did the trick.
>
> Here how I did it:
>
> pp-o packed_script--reusable main_script.pl
>
> #############################################################
> # part in the main_script.pl where the helper script is invoked
> #############################################################
>
> my $cmd;
> if( defined $ENV{PAR_TEMP} )
> {
>      $cmd = "$0 --par-options --reuse helper_script.pl";
> }
> else
> {
>      $cmd = "perl helper_script.pl";
> }
>
> # execute external command
>
> Problems which still have to be solved. Help is welcome.
>
> 1.) helper_script.pl is not part of the packed executable
> --> helper_script.pl shall be within the packed executable
>
> 2.) needed modules of "helper_script.pl" also have to be part of the 
> packed executable
>
> The solution is near. I hope you can help me to fix the last two open 
> points. I'll investigate too and post updates when I know more.
>
> Cheers,
> Dirk
>
> Am 14.03.2012 22:04, schrieb Dirk Joos:
>>
>> -- 
>> Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail 
>> gesendet.
>>
>> ------------------------------------------------------------------------
>> *Von:* Dirk Joos <dirk@dirkundsari.de>
>> *Gesendet:* Wed Mar 14 16:59:39 MEZ 2012
>> *An:* Roderich Schupp <roderich.schupp@googlemail.com>
>> *CC:* par@perl.org
>> *Betreff:* Re: Packing multiple scripts in a standalone executable 
>> with pp
>>
>> You are right. Using several separately packed scripts would be too 
>> much runtime overhead. And this would lead to several packed files 
>> although I would prefer a single file.
>>
>> But I discovered the --reusable option of pp. When reading the 
>> documentation I thought that this is exactly what I need.
>> Of course there are then two variants of the script. A packed one and 
>> a normal one. But one more if statement wouldn't matter.
>>
>> Am I right? Is the --reusable option of pp possibly the thing I'm 
>> looking for?
>>
>> Thank you.
>>
>> Cheers, Dirk
>>
>>
>>
>> Roderich Schupp <roderich.schupp@googlemail.com> schrieb:
>>
>>     On Wed, Mar 14, 2012 at 13:58, Dirk Joos<dirk@dirkundsari.de>  wrote:
>>     >  And sorry for asking again. Why isn't it planned?
>>
>>     Because... there is no plan (at least I don't have one).
>>
>>     >  Don' t you think that this would be an important feature?
>>
>>     No, I don't think so.
>>
>>     >  What could be a workaround? Perhaps packing each script separately and then
>>     >  calling the packed stuff instead of using a second perl interpreter?
>>
>>     Sure, if your're willing to accept the runtime overhead.
>>     It also means that you would have two variants of your program -
>>     one when running normaly, the other when running packed.
>>
>>     Cheers, Roderich
>>
>>
>> -- 
>> Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail 
>> gesendet. 
>



Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About