ProcessTable/Role/Process/OS/MSWin32.pm untested

filter: Statementstmt 0.0% 0 / 43 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 69 CC 4 SCAR 20.2
CC
4
Cov
0%
kill
20.0
BEGIN
2.0
_win32_proc
2.0
CRAP 7.5
1 package P9Y::ProcessTable::Role::Process::OS::MSWin32;
2  
3 our $AUTHORITY = 'cpan:BBYRD'; # AUTHORITY
4 our $VERSION = '1.06_01'; # VERSION
5  
6 #############################################################################
7 # Modules
8  
9 # use sanity;
10 use strict qw(subs vars);
11 no strict 'refs';
12 use warnings FATAL => 'all';
13 no warnings qw(uninitialized);
14  
15 use Moo::Role;
16  
17 ### FIXME: Can't get Win32::API to not crash on me... ###
18  
19 use Win32::Process;
20 #use Win32::API;
21 #use Win32::API::Callback;
22  
23 BEGIN {
24 #Win32::API->Import( 'user32', 'EnumWindows', 'KN', 'N' );
25 #Win32::API->Import( 'user32', 'GetWindowThreadProcessId', 'NP', 'N' );
26 #Win32::API->Import( 'user32', 'PostMessage', 'NINN', 'N' );
27 }
28  
29 no warnings 'uninitialized';
30  
31 my $pi = Win32::Process::Info->new();
32  
33 my $IS_CYGWIN = ($^O =~ /cygwin/i) ? 1 : 0;
34  
35 #############################################################################
36 # Methods
37  
38 sub _win32_proc {
39 my $self = shift;
40 my $obj;
41 Win32::Process::Open($obj, $self->pid, 0);
42 return $obj;
43 }
44  
45 sub kill {
46 my ($self, $sig) = @_;
47  
48 # Windows's signal.h actually has plenty of gaps, but it still follows Linux's model where
49 # there isn't gaps. Thus, we'll just fill in the blanks.
50  
51 # POSIX = 0 HUP INT QUIT ILL TRAP ABRT . FPE KILL . SEGV . PIPE ALRM TERM . . . . . . ABRT
52 # 0x0010 = WM_CLOSE
53 my $posix2wm = [
54 0, 0x0010, 0x0010, qw/kill kill kill kill . kill kill . kill ./, 0x0010, 0x0010, 0x0010, qw/. . . . . . kill/
55 ];
56  
57 $sig = $posix2wm->[$sig];
58 return if (!$sig || $sig eq '.');
59 if ($sig eq '0') {
60 return CORE::kill($sig, $self->pid);
61 }
62 elsif ($sig eq 'kill') {
63 return $self->_win32_proc->Kill(255);
64 }
65 else {
66 #my $cb = Win32::API::Callback->new( sub {
67 # my $hwnd = shift;
68 # my $pid = 0;
69 #
70 # #GetWindowThreadProcessId($hwnd, \$pid);
71 # print "foo\n";
72 # #PostMessage($hwnd, $sig) if ($$pid && $$pid == $self->pid);
73 #}, "NN", "N" );
74 #
75 #my $ret = EnumWindows($cb, 0);
76 return $self->_win32_proc->Kill(255);
77 }
78 }
79  
80 around priority => sub {
81 my ($orig, $self, $pri) = @_;
82 return $orig->($self) if @_ == 2;
83  
84 $self->_win32_proc->SetPriorityClass($pri);
85 $self->_set_priority($pri);
86 };
87  
88 42;