Packager/MSWin.pm untested

filter: Statementstmt 0.0% 0 / 81 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 18 Podpod 0.0% 0 / 11 totaltotal 0.0% 0 / 129 CC 4 SCAR 11.5
CC
4
Cov
0%
delete_file
6.0
prepare_pdkcheck
6.0
_set_mingwdll
6.0
CRAP 3.1
1 ###################################################################################
2 # Distribution Wx::Perl::Packager
3 # File Wx/Perl/Packager/MSWin.pm
4 # Description: module for MSWin specific handlers
5 # File Revision: $Id: MSWin.pm 48 2010-04-25 00:26:34Z $
6 # License: This program is free software; you can redistribute it and/or
7 # modify it under the same terms as Perl itself
8 # Copyright: Copyright (c) 2006 - 2010 Mark Dootson
9 ###################################################################################
10 package Wx::Perl::Packager::MSWin;
11 use strict;
12 use warnings;
13 require Wx::Perl::Packager::Base;
14 use base qw( Wx::Perl::Packager::Base );
15 use Win32;
16 use Win32::File;
17  
18 our $VERSION = '0.27';
19  
20 sub new {
21 my $class = shift;
22 my $self = $class->SUPER::new( @_ );
23 return $self;
24 }
25  
26 sub config_system {
27 my $self = shift;
28  
29 $self->set_so_module_suffix(''); # different linux dists symlink the .so libraries differently
30 # BAH. the loaders in Wx::Perl::Packager will look for
31 # modules ending in '.so' - If your modules get packaged
32 # differently, put the suffix here.
33 # e.g. if your module when packaged is
34 # wxlibs_gcc_base.so.0.6.0
35 # you should $self->set_so_module_suffix('.0.6.0')
36
37 $self->set_relocate_pdkcheck(0); # relocate the Wx dlls during PDK Check - never necessary it seems
38
39 $self->set_relocate_packaged(1); # relocate the Wx Dlls when running as PerlApp
40
41 $self->set_relocate_wx_main(1); # if set_relocate_packaged is true and we find 'wxmain.dll'
42 # as a bound file, we load it as Wx.dll ( which it should be
43 # if user as bound it). This is the current fix for PerlApp
44 # segmentation fault on exit in Linux. Makes no difference
45 # in MSWin
46
47 $self->set_unlink_relocated(1); # delete the extracted files - ensures relocated are loaded
48
49 $self->set_loadmode_pdkcheck('nullsub'); # standard | nullsub | packload during pdkcheck
50 # standard uses normal Wx loading
51 # nullsub - no extensions are loaded
52 # packload - extensions are loaded by Wx::Perl::Packager
53  
54 $self->set_loadmode_packaged('packload');# as above, when running as PerlApp
55
56 $self->set_loadcore_pdkcheck(0); # use DynaLoader to load wx modules listed by
57 # get_core_modules method (below)during pdkcheck
58
59 $self->set_loadcore_packaged(1); # as above, when running as PerlApp
60
61 $self->set_unload_loaded_core(1);# unload any librefs we loaded
62 # (uses DynaLoader in an END block )
63
64 $self->set_unload_loaded_plugins(1); # unload plugins ( html, stc, gl .. etc) that are
65 # loaded via 'packload'. This seems to be necessary
66 # to ensure correct unloading order.
67 # Note - plugins are loaded using
68 # Wx::_load_plugin (not DynaLoader);
69
70 $self->set_pdkcheck_exit(0); # because of the current seg fault on exit in linux
71 # you can't package using PerlApp
72 # setting this to '1' calls 'exit(0)' after
73 # Wx has loaded during pdkcheck
74 # Drastic - but it is the current hack for this failure on linux
75
76 $self->set_pdkcheck_handle(1); # if true, use special handling during pdkcheck
77 # if false, treat as standard perl ( all other pdkcheck
78 # options are ignored)
79
80 $self->SUPER::config_system;
81 }
82  
83  
84 sub delete_file {
85 my( $self, $target) = @_;
86 return if !-f $target;
87 my $attribs = Win32::File::NORMAL|Win32::File::TEMPORARY;
88 Win32::File::SetAttributes($target, $attribs);
89 unlink $target;
90 }
91  
92 sub compare_paths {
93 my($self, $one, $two) = @_;
94 $one =~ s/\//\\/g;
95 $two =~ s/\//\\/g;
96 $one = lc(Win32::GetLongPathName($one));
97 $two = lc(Win32::GetLongPathName($two));
98 return ( $one eq $two );
99 }
100  
101 sub get_core_modules { (qw( mingw gdiplus base core adv )) }
102  
103 sub config_modules {
104 my $self = shift;
105
106 $self->get_modules->{wx} = { filename => 'wxmain.dll', loaded => 0, libref => undef, missing_fatal => 0 };
107
108 $self->get_modules->{mingw} = { filename => 'mingwm10.dll', loaded => 0, libref => undef, missing_fatal => 0 };
109 # keep backwards compatibility with gdiplus hack
110 $self->get_modules->{gdiplus} = { filename => 'gdiplus.dll', loaded => 0, libref => undef, missing_fatal => 0 };
111
112 $self->SUPER::config_modules;
113 }
114  
115 sub setsys_filepath {
116 my($self, $filepath) = @_;
117 $filepath =~ s/\//\\/g;
118 $filepath = Win32::GetLongPathName($filepath) || $filepath;
119 return $filepath;
120 }
121  
122 sub prepare_perl {
123 my $self = shift;
124 $self->_set_mingwdll( $self->get_wx_load_path );
125 };
126  
127 sub prepare_pdkcheck {
128 my $self = shift;
129 $self->_set_mingwdll( $self->get_wx_load_path );
130 $ENV{PATH} = $self->get_wx_load_path . ';' . $ENV{PATH};
131
132 # mingw-w64 built Wx will fault on pdkcheck exit ?
133 my $mdll = $self->get_modules->{mingw}->{filename};
134 if($mdll =~ /^libgcc/) {
135 $self->set_pdkcheck_exit(1);
136 }
137 }
138  
139 sub prepare_perlapp {
140 my $self = shift;
141 require Wx::Perl::Packager::Mini;
142 $self->_set_mingwdll( $self->get_app_extract_path );
143 }
144  
145 sub _set_mingwdll {
146 my($self, $dir) = @_;
147 my $defaultmingw = 'mingwm10.dll';
148 opendir(MYWXDIR, $dir) or die qq(Unable to open directory $dir : $!);
149 my @mingfiles = grep { /^libgcc_/ } readdir(MYWXDIR);
150 closedir(MYWXDIR);
151 if($mingfiles[0] && (-f qq($dir/$mingfiles[0]))) {
152 $defaultmingw = $mingfiles[0];
153 }
154 $self->debug_print(qq(mingw runtime is $defaultmingw));
155 $self->get_modules->{mingw}->{filename} = $defaultmingw;
156 }
157  
158  
159  
160 1;