Wx-Perl-Packager

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

Revision history for Wx-Perl-Packager

0.27    2010-09-16 00:00
        Essential bug-fix for wx relocation in PerlApp

0.26    2010-04-15 00:00
        POD changes only for MacOSX
        wxpar improved handling for Linux binary names and improved POD
        wxpar now picks up runtime library for mingw-w64 built binaries

0.25    2010-04-13 00:00
        Fixed for MacOSX 10.4

0.24    2010-03-27 00:00

lib/Wx/Perl/Packager.pm  view on Meta::CPAN

    options. Mix and match if you think there's a better way.
    
    $self->set_so_module_suffix(''); # different linux dists symlink the .so libraries differently
                                     # BAH. the loaders in Wx::Perl::Packager will look for
                                     # modules ending in '.so'  - If your modules get packaged
                                     # differently, put the suffix here.
                                     # e.g. if your module when packaged is
                                     # wxlibs_gcc_base.so.0.6.0
                                     # you should $self->set_so_module_suffix('.0.6.0')
    
    $self->set_relocate_pdkcheck(0); # relocate the Wx dlls during PDK Check - never necessary it seems
    
    $self->set_relocate_packaged(1); # relocate the Wx Dlls when running as PerlApp
    
    $self->set_relocate_wx_main(1);  # if set_relocate_packaged is true and we find 'wxmain.so'
                                     # as a bound file, we load it as Wx.so ( which it should be
                                     # if user as bound it). This is the current fix for PerlApp
                                     # segmentation fault on exit in Linux. Makes no difference
                                     # in MSWin
    
    $self->set_unlink_relocated(1);  # delete the extracted files - ensures relocated are loaded
    
    $self->set_loadmode_pdkcheck('packload'); # standard | nullsub | packload  during pdkcheck
                                              # standard uses normal Wx loading
                                              # nullsub - no extensions are loaded
                                              # packload - extensions are loaded by Wx::Perl::Packager

    $self->set_loadmode_packaged('packload');# as above, when running as PerlApp
    
    $self->set_loadcore_pdkcheck(1); # use DynaLoader to load wx modules listed by
                                     # get_core_modules method (below)during pdkcheck

lib/Wx/Perl/Packager/Base.pm  view on Meta::CPAN

our $VERSION = '0.27';

#-------------------------------------
# Accessors
#-------------------------------------

__PACKAGE__->follow_best_practice; # I like get/set

__PACKAGE__->mk_ro_accessors( qw( config debug_on is_mswin is_darwin is_linux path_delim dll_suffix) );

__PACKAGE__->mk_accessors( qw( relocate_pdkcheck relocate_packaged
    loadmode_pdkcheck loadmode_packaged loadcore_pdkcheck loadcore_packaged relocateable core_relocated require_overwrite 
    inner_wx_load_path inner_app_extract_path inner_app_relocate_path packaged runtime pdkautopackaged basemodule
    modules unload_loaded_core core_loaded so_module_suffix path_separator pdkcheck_exit unload_loaded_plugins
    unlink_relocated relocate_wx_main pdkcheck_handle
    ));

#---------------------------------------
# Constructor with default configuration
#---------------------------------------

sub new {
    my $class = shift;
    my $self = $class->SUPER::new( {
        debug_on            => $Wx::Perl::Packager::_debug_print_on,
        relocate_pdkcheck   => 0,
        relocate_packaged   => 0,
        relocate_wx_main    => 0,
        loadmode_pdkcheck   => 'standard',  # standard | nullsub | packload
        loadmode_packaged   => 'packload',
        loadcore_pdkcheck   => 0,
        loadcore_packaged   => 0,
        unload_loaded_core  => 1,
        unload_loaded_plugins => 1,
        require_overwrite   => 0,
        runtime             => 'PERL',
        packaged            => 0,
        path_delim          => ( $^O =~ /^mswin/i ) ? ';' : ':',
        dll_suffix          => ( $^O =~ /^mswin/i ) ? '.dll' : '.so',
        relocateable        => 0,
        core_relocated      => 0,
        core_loaded         => 0,
        pdkautopackaged     => 0,
        pdkcheck_exit       => 0,
        pdkcheck_handle     => 0,
        unlink_relocated    => 0,
        path_separator      => ( $^O =~ /^mswin/i ) ? "\\" : '/',
        is_mswin            => ( $^O =~ /^mswin/i ) ? 1 : 0,
        is_linux            => ( $^O =~ /^linux$/i ) ? 1 : 0,
        is_darwin           => ( $^O =~ /^darwin$/i ) ? 1 : 0,
        inner_wx_load_path      => ( $Wx::wx_path ) ? $Wx::wx_path : '',
        inner_app_extract_path  => '',
        inner_app_relocate_path => '',
        modules             => {},
        so_module_suffix    => '',
        }
    );
    $self->debug_print('Initial wx_path is : ' . $self->get_wx_load_path);
    
    return $self;
}

sub cleanup_on_exit { $_[0]->debug_print('Clean up on Exit'); }

lib/Wx/Perl/Packager/Base.pm  view on Meta::CPAN

    #----------------------------------------------------
    
    return if $runtime eq 'PERL';
    
    $self->debug_print('Preparing Load Paths for Wx');
    
    $self->prepare_load_paths;
    
    $self->debug_print('Load Paths Complete');
    
    my $requestrelocate;
    if($runtime eq 'PDKCHECK') {
        $requestrelocate = $self->get_relocate_pdkcheck;
    } elsif( $runtime eq 'PERLAPP') {
        $requestrelocate = $self->get_relocate_packaged;
    }
    
    if ($self->get_relocateable && $requestrelocate) {
        $self->debug_print('Relocating extracted modules for Wx');
        $self->relocate_wx;
        $self->debug_print('Relocation Complete');
    }
    
    $self->debug_print('Preparing and Loading Wx');
    
    #################################################################
    
    $self->run_wx_start; # THIS LOADS WX
    
    #################################################################

lib/Wx/Perl/Packager/Base.pm  view on Meta::CPAN

        
    } elsif($ENV{PAR_0} && -f($ENV{PAR_0})) {
        $self->set_runtime('PARLEXE');
        $self->set_packaged(1);
    } else {
        # we are perl - reiterate defaults
        $self->set_runtime('PERL');
        $self->set_packaged(0);
    }
    #------------------------------------------------------------
    # set the extract paths and relocate paths
    #------------------------------------------------------------
    
    #------------------------------------
    # RUNTIME PERL
    #------------------------------------
        
    if($self->get_runtime() eq 'PERL') {
        $self->set_relocateable(0);
            
    #------------------------------------
    # RUNTIME PERLAPP & PDKCHECK
    #------------------------------------
    
    } elsif($PerlApp::VERSION) {
        #--------------------------------
        # IS Wx In the PerlApp::RUNLIB
        #--------------------------------
        my $perlappset = 0;
        my $basemodule = $self->get_basemodule;
        my $runlib = $PerlApp::RUNLIB;
        if( $runlib && (-d $PerlApp::RUNLIB )) {
            my $checkpath = $PerlApp::RUNLIB . '/' . $basemodule;
            if(-f  $checkpath ) {
                $self->set_pdkautopackaged(0);
                $self->set_relocateable(0);
                $self->set_wx_load_path( $checkpath );
                $perlappset = 1;
                
                # final check
                die qq(Cannot find directory $checkpath) if !-d $checkpath;
                
            }
        }
        #--------------------------------
        # Were Wx modules bound manually
        #--------------------------------
        if( !$perlappset ) {
            my $basefile = PerlApp::extract_bound_file($basemodule);
            # user packaged
            if( $basefile ) {
                if($basefile =~ /^(.*)[\\\/]\Q$basemodule\E$/) {
                    my $regpath = $1;
                    die qq(Cannot find directory $regpath) if !-d $regpath;
                    $self->set_app_extract_path($regpath);
                    $self->set_wx_load_path($regpath);
                    $self->set_relocateable(1);
                    $self->set_pdkautopackaged(0);
                    $perlappset = 1;
                    # final check
                }
        #------------------------------------------
        # OR Were Wx modules bound by PDK heuristic
        #------------------------------------------
            } else {
            # perlapp packaged (we hope )
                $self->set_pdkautopackaged(1);

lib/Wx/Perl/Packager/Base.pm  view on Meta::CPAN

                    my $wxmainfile = $self->get_module_filename('wx');
                    $self->debug_print(qq(Module Mainfile Path is $wxmainfile));
                    my $dllfile = PerlApp::extract_bound_file($wxmainfile);
                    if($dllfile && -f $dllfile) {
                        $self->debug_print(qq(Module Mainfile FilePath is $dllfile));
                        if($dllfile =~ /^(.*)[\\\/]\Q$wxmainfile\E$/) {
                            my $regpath = $1;
                            die qq(Cannot find directory $regpath) if !-d $regpath;
                            $self->set_app_extract_path($regpath);
                            $self->set_wx_load_path($regpath);
                            $self->set_relocateable(1);
                            $perlappset = 1;
                            
                        }
                    }
                }
                if(!$perlappset) {
                #-------------------------------------------------
                # user may also set a marker 'wxextractmarker'
                #-------------------------------------------------
                    my $markerfile = PerlApp::extract_bound_file('wxextractmarker');
                    if($markerfile && -f $markerfile) {
                        if($markerfile =~ /^(.*)[\\\/]wxextractmarker$/) {
                            my $regpath = $1;
                            die qq(Cannot find directory $regpath) if !-d $regpath;
                            $self->set_app_extract_path($regpath);
                            $self->set_wx_load_path($regpath);
                            $self->set_relocateable(1);
                            $perlappset = 1;
                        }
                    }
                }
                if(!$perlappset) {
                #-------------------------------------------------
                # No handy marker :-(
                #-------------------------------------------------
                    # check the first item in the path
                    # if author has placed Wx::Perl::Packager at start of

lib/Wx/Perl/Packager/Base.pm  view on Meta::CPAN

                    # path as unexpected stuff may (will) happen
                    # if we traverse further
            
                    my $delim = $self->get_path_delim();
                    my @envpaths = split(/$delim/, $ENV{PATH});
                    my $pdkdirpath = shift @envpaths;
                    $pdkdirpath =~ s/\\/\//g;
                    $pdkdirpath =~ s/\/$//;
                    my $fpath = qq($pdkdirpath/$basemodule);
                    if($fpath && (-f $fpath)) {
                        $self->set_relocateable(1);
                        $perlappset = 1;
                        $self->set_app_extract_path($pdkdirpath);
                        $self->set_wx_load_path($pdkdirpath);
                    }
                }
            }
        }
    #------------------------------------
    # RUNTIME PARLEXE
    #------------------------------------
    
    } elsif($self->get_runtime() eq 'PARLEXE') {
        $self->set_relocateable(0);
        # the extract path we get from PAR
        # could be wxlib + module
        # or just module
        my @ldpath = split(/[\\\/]/, $ENV{PAR_0});
        pop(@ldpath);
        my $loadpath = join('/', @ldpath);
        $self->set_app_extract_path($loadpath);
        $self->set_wx_load_path($loadpath);
    }
}

lib/Wx/Perl/Packager/Base.pm  view on Meta::CPAN

}

sub prepare_parlexe { 1;}

sub prepare_load_paths {
    my $self = shift;
    my $loadpath = $self->get_wx_load_path;
    $self->debug_print(qq(Load Path set $loadpath));
}

sub relocate_wx {
    my $self = shift;
    
    # set the relocate path
    $self->config_relocate_path;
    
    my @core = $self->get_core_modules;
    
    my $targetpath = $self->get_app_relocate_path;
    $self->debug_print(qq(Relocate Path is $targetpath));
    die 'relocate path does not exist' if !-d $targetpath;
    
    my $sourcepath = $self->get_app_extract_path;
    $self->debug_print(qq(Extract Path is $sourcepath));
    die 'extract path does not exist' if !-d $sourcepath;
    
    my $forcewrite = $self->get_require_overwrite;

    for my $dllkey ( @core, 'wx' ) { 
        next if !$self->module_exists($dllkey);
        next if(($dllkey eq 'wx') && (!$self->get_relocate_wx_main));
        my $modulefile = $self->get_module_filename($dllkey);
        my $targetmodulepath = qq($targetpath/$modulefile);
        my $sourcemodulepath = qq($sourcepath/$modulefile);
        next if !-f $sourcemodulepath;
        my $copyrequired = 0;
        $copyrequired = 1 if !-f $targetmodulepath;
        $copyrequired = 1 if $forcewrite;
        if( $copyrequired ) {
            $self->delete_file($targetmodulepath);
            $self->copy_file($sourcemodulepath, $targetmodulepath) 
        }
        $self->delete_file($sourcemodulepath) if $self->get_unlink_relocated;
        $self->debug_print(qq(Relocated $dllkey));
    }
    
    $self->set_core_relocated(1);
    
}

sub do_core_load {
    my $self = shift;
    my $runtime = $self->get_runtime;
    my $coreload = 0;
    if($runtime eq 'PDKCHECK') {
        $coreload = $self->get_loadcore_pdkcheck;
        

lib/Wx/Perl/Packager/Base.pm  view on Meta::CPAN

                                 $self->debug_print(qq(Unloading Plugin $modulefilename));
                                 Wx::_unload_plugin( $modulefilename );
                            }
                        }
                        
                        # if we don't specifically unload dl refs, we get a fault on
                        # exit if we close the app immediatley after startup without
                        # interacting with controls (e.g STC) from the keyboard
                        
                        # conversely, the rmtree command fails when we DO interact
                        # with controls from the keyboard - which is why we  relocate
                        # to a 'permanent' dir for MSWin
                        
                        if( ( $self->get_core_loaded ) && ( $self->get_unload_loaded_core ) ) {
                        
                            my @core = $self->get_core_modules;
                            
                            while(my $dll = pop(@core) ) {
                                my $libref = $self->get_modules->{$dll}->{libref};
                                if ($libref) {
                                    $self->debug_print( qq(Unloading Core Module $dll) );

lib/Wx/Perl/Packager/Base.pm  view on Meta::CPAN

}


#------------------------------
# Overloads for paths
#------------------------------

sub set_app_extract_path { $_[0]->set_inner_app_extract_path( $_[0]->setsys_filepath($_[1]) ); }
sub get_app_extract_path { $_[0]->get_inner_app_extract_path; }

sub set_app_relocate_path { $_[0]->set_inner_app_relocate_path( $_[0]->setsys_filepath($_[1]) ); }
sub get_app_relocate_path { $_[0]->get_inner_app_relocate_path; }

sub set_wx_load_path { $_[0]->set_inner_wx_load_path( $_[0]->setsys_filepath($_[1]) ); }
sub get_wx_load_path { $_[0]->get_inner_wx_load_path; }
    
sub module_exists { exists($_[0]->get_modules->{$_[1]} ); }

sub get_module_filename { $_[0]->module_exists($_[1]) ? $_[0]->get_modules->{$_[1]}->{filename} : undef; }

sub get_module_wx_load_path {
    if(my $filename = $_[0]->get_module_filename($_[1])) {
        my $wxpath = $_[0]->get_wx_load_path();
       
        return ( $wxpath ) ? $wxpath . $_[0]->get_path_separator . $filename : $filename;
    } else {
        return undef;
    }
}

sub get_module_app_relocate_path {
    if(my $filename = $_[0]->get_module_filename($_[1])) {
        my $dirpath = $_[0]->get_app_relocate_path();
        
        return $dirpath . $_[0]->get_path_separator . $filename;
    } else {
        return undef;
    }
}

sub get_module_app_extract_path {
    if(my $filename = $_[0]->get_module_filename($_[1])) {
        my $dirpath = $_[0]->get_app_extract_path();
        
        return $dirpath . $_[0]->get_path_separator . $filename;
    } else {
        return undef;
    }
}

sub get_module_core_load_path {
    if(my $filename = $_[0]->get_module_filename($_[1])) {
        my $dirpath = ( $_[0]->get_core_relocated ) 
            ? $_[0]->get_app_relocate_path
            : $_[0]->get_wx_load_path;
        my $sep = ( $_[0]->get_is_mswin ) ? "\\" : '/';
        
        return ( $dirpath ) ? $dirpath . $sep . $filename : $filename;
    } else {
        return undef;
    }
}
    
sub setsys_filepath {
    my($self, $filepath) = @_;
    $filepath =~ s/\\/\//g;
    return $filepath;
}


#------------------------------------------
# If we have no alternative but to relocate
# wx dlls ........
#------------------------------------------

sub config_relocate_path {
    my $self = shift;
    return if !$self->get_relocateable(); # just in case
    
    # app extract path is writable by us - so create our wxlib extract
    # files side by side
    
    my $appextractpath = $self->get_app_extract_path();
    die qq(error in determining extract paths) if !-d $appextractpath;
    
    # determine where the standard PDK path is
    
    # get a unique extract directory for this application build
    my $runtime = $self->get_runtime();
    my $uid = getlogin || (getpwuid($<))[0];
    my $toplevel = 'wxppl-' . $uid;
    $toplevel =~ s/[^A-Za-z0-9\-_]/_/g;
    
    my $apprelocatedir;
    
    if($runtime eq 'PERLAPP') {
        # get a unique dir for this build in this location
        my $ctx = Digest::MD5->new;
        my $exec = PerlApp::exe();
        $ctx->add( $exec  );
        my $basestatfile = $appextractpath . '/' . $self->get_basemodule();
        $self->debug_print(qq(Base Core extracted module = $basestatfile));
        my $filestat = (-f $basestatfile ) ? (stat($basestatfile))[7]: 'fixed data';
        $ctx->add( $filestat );
        
        if($self->get_relocate_wx_main) {
            # we also relocate wxmain - which means we have to add that to uniqueness
            if( my $wxmain = $self->get_module_filename('wx') ) {
                my $mainstatfile = $appextractpath . '/' . $wxmain;
                $self->debug_print(qq(Wx Main extracted module = $mainstatfile));
                my $mainfilestat = (-f $mainstatfile ) ? (stat($mainstatfile))[7]: 'wxmain data';
                $ctx->add( $mainfilestat );
            }
        }
        
        $apprelocatedir = $ctx->hexdigest;
        
    }   elsif( $runtime eq 'PDKCHECK' ) {
        # we keep the same dir and overwrite
        $apprelocatedir = 'PDKCHECKBUILDING';
    }
    
    # build the directories
    my @paths = split(/[\/\\]/, $appextractpath);
    pop(@paths);
    my $apprunpath = join('/', (@paths, $toplevel));
    mkdir($apprunpath, 0700) if !-d $apprunpath;
    $apprunpath .= '/' . $apprelocatedir;
    mkdir($apprunpath, 0700) if !-d $apprunpath;
    
    $self->set_app_relocate_path($apprunpath);
}

1;

lib/Wx/Perl/Packager/Linux.pm  view on Meta::CPAN

    my $self = shift;
    
    $self->set_so_module_suffix('.0'); # different linux dists symlink the .so libraries differently
                                     # BAH. the loaders in Wx::Perl::Packager will look for
                                     # modules ending in '.so'  - If your modules get packaged
                                     # differently, put the suffix here.
                                     # e.g. if your module when packaged is
                                     # wxlibs_gcc_base.so.0.6.0
                                     # you should $self->set_so_module_suffix('.0.6.0')
    
    $self->set_relocate_pdkcheck(0); # relocate the Wx dlls during PDK Check - never necessary it seems
    
    $self->set_relocate_packaged(1); # relocate the Wx Dlls when running as PerlApp
    
    $self->set_relocate_wx_main(1);  # if set_relocate_packaged is true and we find 'wxmain.so'
                                     # as a bound file, we load it as Wx.so ( which it should be
                                     # if user as bound it). This is the current fix for PerlApp
                                     # segmentation fault on exit in Linux. Makes no difference
                                     # in MSWin
    
    $self->set_unlink_relocated(1);  # delete the extracted files - ensures relocated are loaded
    
    $self->set_loadmode_pdkcheck('packload'); # standard | nullsub | packload  during pdkcheck
                                              # standard uses normal Wx loading
                                              # nullsub - no extensions are loaded
                                              # packload - extensions are loaded by Wx::Perl::Packager

    $self->set_loadmode_packaged('packload');# as above, when running as PerlApp
    
    $self->set_loadcore_pdkcheck(1); # use DynaLoader to load wx modules listed by
                                     # get_core_modules method (below)during pdkcheck

lib/Wx/Perl/Packager/MSWin.pm  view on Meta::CPAN

    my $self = shift;

    $self->set_so_module_suffix(''); # different linux dists symlink the .so libraries differently
                                     # BAH. the loaders in Wx::Perl::Packager will look for
                                     # modules ending in '.so'  -  If your modules get packaged
                                     # differently, put the suffix here.
                                     # e.g. if your module when packaged is
                                     # wxlibs_gcc_base.so.0.6.0
                                     # you should $self->set_so_module_suffix('.0.6.0')
    
    $self->set_relocate_pdkcheck(0); # relocate the Wx dlls during PDK Check - never necessary it seems
    
    $self->set_relocate_packaged(1); # relocate the Wx Dlls when running as PerlApp
    
    $self->set_relocate_wx_main(1);  # if set_relocate_packaged is true and we find 'wxmain.dll'
                                     # as a bound file, we load it as Wx.dll ( which it should be
                                     # if user as bound it). This is the current fix for PerlApp
                                     # segmentation fault on exit in Linux. Makes no difference
                                     # in MSWin
    
    $self->set_unlink_relocated(1);  # delete the extracted files - ensures relocated are loaded
    
    $self->set_loadmode_pdkcheck('nullsub'); # standard | nullsub | packload  during pdkcheck
                                             # standard uses normal Wx loading
                                             # nullsub - no extensions are loaded
                                             # packload - extensions are loaded by Wx::Perl::Packager

    $self->set_loadmode_packaged('packload');# as above, when running as PerlApp
    
    $self->set_loadcore_pdkcheck(0); # use DynaLoader to load wx modules listed by
                                     # get_core_modules method (below)during pdkcheck

lib/Wx/Perl/Packager/MacOSX.pm  view on Meta::CPAN

sub config_system {
    my $self = shift;
    $self->set_so_module_suffix(''); # different linux dists symlink the .so libraries differently
                                     # BAH. the loaders in Wx::Perl::Packager will look for
                                     # modules ending in '.so'  -  If your modules get packaged
                                     # differently, put the suffix here.
                                     # e.g. if your module when packaged is
                                     # wxlibs_gcc_base.so.0.6.0
                                     # you should $self->set_so_module_suffix('.0.6.0')
    
    $self->set_relocate_pdkcheck(0); # relocate the Wx dlls during PDK Check - never necessary it seems
    
    $self->set_relocate_packaged(1); # relocate the Wx Dlls when running as PerlApp
    
    $self->set_relocate_wx_main(1);  # if set_relocate_packaged is true and we find 'wxmain.dll'
                                     # as a bound file, we load it as Wx.dll ( which it should be
                                     # if user as bound it). This is the current fix for PerlApp
                                     # segmentation fault on exit in Linux. Makes no difference
                                     # in MSWin
    
    $self->set_unlink_relocated(0);  # delete the extracted files - ensures relocated are loaded
    
    $self->set_loadmode_pdkcheck('standard'); # standard | nullsub | packload  during pdkcheck
                                             # standard uses normal Wx loading
                                             # nullsub - no extensions are loaded
                                             # packload - extensions are loaded by Wx::Perl::Packager

    $self->set_loadmode_packaged('standard');# as above, when running as PerlApp
    
    $self->set_loadcore_pdkcheck(0); # use DynaLoader to load wx modules listed by
                                     # get_core_modules method (below)during pdkcheck



( run in 1.186 second using v1.01-cache-2.11-cpan-71847e10f99 )