blib/lib/Test/Smoke/Util/Win32ErrorMode.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 55 CC 4 SCAR 17.6
CC
4
Cov
0%
lower_error_settings
12.0
BEGIN
6.0
BEGIN
2.0
CRAP 5.8
1 package Test::Smoke::Util::Win32ErrorMode;
2 use warnings;
3 use strict;
4  
5 our $VERSION = '0.001';
6  
7 BEGIN {
8 if ($^O eq 'MSWin32') {
9 require Win32::API;
10 require Win32;
11 }
12 else {
13 warn "# This is not MSWin32, don't try to use this module on $^O\n";
14 }
15 }
16  
17 sub lower_error_settings {
18 return if $^O ne 'MSWin32';
19 # Call kernel32.SetErrorMode(SEM_FAILCRITICALERRORS):
20 # "The system does not display the critical-error-handler message box.
21 # Instead, the system sends the error to the calling process." and
22 # "A child process inherits the error mode of its parent process."
23 {
24 my $SetErrorMode = Win32::API->new('kernel32', 'SetErrorMode', 'I', 'I');
25 my $SEM_FAILCRITICALERRORS = 0x0001;
26 my $SEM_NOGPFAULTERRORBOX = 0x0002;
27 $SetErrorMode->Call($SEM_FAILCRITICALERRORS | $SEM_NOGPFAULTERRORBOX);
28 }
29  
30 # Set priority just below normal (on Win2K and later)
31 {
32 my (undef, $major, undef, undef, $id) = Win32::GetOSVersion();
33 if ($id == 2 && $major >= 5 && eval { require Win32::Process }) {
34 Win32::Process::Open(my $proc, $$, 0);
35  
36 # constant not defined by older Win32::Process versions
37 my $BELOW_NORMAL_PRIORITY_CLASS = 0x00004000;
38 $proc->SetPriorityClass($BELOW_NORMAL_PRIORITY_CLASS);
39 }
40 }
41 }
42  
43 1;
44  
45 =head1 NAME
46  
47 Test::Smoke::Util::Win32ErrorMode - Utility function to switch off the error-popup for the current process.
48  
49 =head1 DESCRIPTION
50  
51 This patch was provided in
52 L<RT-39138|https://rt.cpan.org/Ticket/Display.html?id=39138>. The code has
53 changed quite a bit since then (9 years ago). But it still looked good and sane,
54 so we decided to give it a place in the code.
55  
56 =head2 lower_error_settings()
57  
58 This calls C<kernel32::SetErrorMode> with the flags: C<SEM_FAILCRITICALERRORS>
59 and C<SEM_NOGPFAULTERRORBOX> to prevent popups during crashes.
60  
61 It also calls C<< Win32::Process::Open()->SetPriorityClass() >> as a way to
62 C<renice()> the process.
63  
64 =head1 COPYRIGHT
65  
66 (c) MMVIII Jan Dubois <jdb@cpan.org> original patch
67  
68 (c) MMXVII Abe Timmerman <abeltje@cpan.org> integration into Test::Smoke.
69  
70 =cut