Hi Peter,

Peter Gordon schrieb:
I am using pp to pack a perl application. It happens to be a wxPerl
project and in the example below I have left out all the includes.

I need to read a a file app.xrc from my application. I have used the -a
flag.

Ah, XRC GUI. Can you tell me how I can get wxglade produced XRC files to work with my own Perl subclasses of Wx::* (e.g. Wx::Panel)? For some reason, the following doesn't bind to the MyPanel Wx::Panel subclass:
    <object class="wxPanel" name="panel_1" subclass="MyPanel">
...

Sorry for the off-topic question!

The manual says "By default, files are placed under "/" inside the
package with their original names.". When I tried to see if the file
exists with -e, it fails.

I tried thusly:

pp  -a z:/Utils/Diagnostics/app.xrc -o app_diag.exe app_diag.pl

and thusly:

pp  -a z:/Utils/Diagnostics/app.xrc;/app.xrc -o app_diag.exe
app_diag.pl

Well, the file is placed under '/' in the PAR archive. That doesn't mean it's extracted to somewhere. PAR archives are just ZIPs. pp-produced executables are almost just a perl with a PAR (ZIP) archive appended. Hence you can check the result of your -a by running unzip on your .exe.

Anyhow, I haven't ever had to do this, but accessing a file 't.txt' from a pp-ed .exe or a script would work as follows:

#!/usr/bin/perl
use strict;
use warnings;
use PAR;

if (my $text = PAR::read_file('t.txt')) { # reads from the ZIP
    print "Via PAR\n";
    print $text;
}
elsif(open my $fh, '<', 't.txt') {
    print "Via file\n"; # If not from within a PAR
    print <$fh>;
}
else {
    die "t.txt not found";
}


Now, t.txt can be found in the cache directory to which the pp-ed executable is extracted as well. It should usually by in your temporary folder under .../par-$USER/cache-$MD5SUM/inc/t.txt

Given a .par file, you can access any files in it as follows:
use PAR;
my $handle = PAR::par_handle('foo.par');
die if nto $handle;
print $handle->memberNamed('t.txt')->contents;
# $handle is just an Archive::Zip object

Hope this helps,
Steffen

Reply via email to