File Coverage

blib/lib/P9Y/ProcessTable/Process/Base.pm
Criterion Covered Total %
statement 26 32 81.2
branch 0 4 0.0
condition n/a
subroutine 9 10 90.0
pod 0 2 0.0
total 35 48 72.9


line stmt bran cond sub pod time code
1             package P9Y::ProcessTable::Process::Base;
2              
3             our $AUTHORITY = 'cpan:BBYRD'; # AUTHORITY
4             our $VERSION = '1.07'; # VERSION
5              
6             #############################################################################
7             # Modules
8              
9             # use sanity;
10 3     3   2533 use strict qw(subs vars);
  3         8  
  3         106  
11 3     3   22 no strict 'refs';
  3         6  
  3         85  
12 3     3   100 use warnings FATAL => 'all';
  3         6  
  3         113  
13 3     3   43 no warnings qw(uninitialized);
  3         5  
  3         108  
14              
15 3     3   16 use Moo;
  3         6  
  3         23  
16              
17 3     3   5132 use namespace::clean;
  3         55062  
  3         24  
18 3     3   991 no warnings 'uninitialized';
  3         5  
  3         2466  
19              
20             #############################################################################
21             # Attributes
22              
23             has _pt_obj => (
24             is => 'ro',
25             required => 1,
26             handles => [qw(
27             fields
28             _process_hash
29             )],
30             );
31              
32             has pid => ( is => 'ro', required => 1 );
33             has uid => ( is => 'rwp', predicate => 1 );
34             has gid => ( is => 'rwp', predicate => 1 );
35             has euid => ( is => 'rwp', predicate => 1 );
36             has egid => ( is => 'rwp', predicate => 1 );
37             has suid => ( is => 'rwp', predicate => 1 );
38             has sgid => ( is => 'rwp', predicate => 1 );
39             has ppid => ( is => 'rwp', predicate => 1 );
40             has pgrp => ( is => 'rwp', predicate => 1 );
41             has sess => ( is => 'rwp', predicate => 1 );
42              
43             has cwd => ( is => 'rwp', predicate => 1 );
44             has exe => ( is => 'rwp', predicate => 1 );
45             has root => ( is => 'rwp', predicate => 1 );
46             has cmdline => ( is => 'rwp', predicate => 1 );
47             has environ => ( is => 'rwp', predicate => 1 );
48              
49             has minflt => ( is => 'rwp', predicate => 1 );
50             has cminflt => ( is => 'rwp', predicate => 1 );
51             has majflt => ( is => 'rwp', predicate => 1 );
52             has cmajflt => ( is => 'rwp', predicate => 1 );
53             has ttlflt => ( is => 'rwp', predicate => 1 );
54             has cttlflt => ( is => 'rwp', predicate => 1 );
55             has utime => ( is => 'rwp', predicate => 1 );
56             has stime => ( is => 'rwp', predicate => 1 );
57             has cutime => ( is => 'rwp', predicate => 1 );
58             has cstime => ( is => 'rwp', predicate => 1 );
59             has start => ( is => 'rwp', predicate => 1 );
60             has time => ( is => 'rwp', predicate => 1 );
61             has ctime => ( is => 'rwp', predicate => 1 );
62              
63             has priority => ( is => 'rwp', predicate => 1 );
64             has fname => ( is => 'rwp', predicate => 1 );
65             has state => ( is => 'rwp', predicate => 1 );
66             has ttynum => ( is => 'rwp', predicate => 1 );
67             has ttydev => ( is => 'rwp', predicate => 1 );
68             has flags => ( is => 'rwp', predicate => 1 );
69             has threads => ( is => 'rwp', predicate => 1 );
70             has size => ( is => 'rwp', predicate => 1 );
71             has rss => ( is => 'rwp', predicate => 1 );
72             has wchan => ( is => 'rwp', predicate => 1 );
73             has cpuid => ( is => 'rwp', predicate => 1 );
74             has pctcpu => ( is => 'rwp', predicate => 1 );
75             has pctmem => ( is => 'rwp', predicate => 1 );
76              
77             has winpid => ( is => 'rwp', predicate => 1 );
78             has winexe => ( is => 'rwp', predicate => 1 );
79              
80             #sub fields {
81             # return ( qw/
82             # pid uid gid euid egid suid sgid ppid pgrp sess
83             # cwd exe root cmdline environ
84             # minflt cminflt majflt cmajflt ttlflt cttlflt utime stime cutime cstime start time ctime
85             # priority fname state ttynum ttydev flags threads size rss wchan cpuid pctcpu pctmem
86             # winpid winexe
87             # / );
88             #}
89              
90             #############################################################################
91             # Common Methods (may potentially be redefined with OS-specific ones)
92              
93             sub refresh {
94 0     0 0 0 my ($self) = @_;
95 0         0 my $hash = $self->_process_hash($self->pid);
96 0 0       0 return unless $hash;
97              
98             # use set methods
99 0         0 foreach my $meth (keys %$hash) {
100 3     3   28 no strict 'refs';
  3         5  
  3         969  
101 0 0       0 $self->("_set_$meth")($hash->{$meth}) if (exists $hash->{$meth});
102             }
103              
104 0         0 return $self;
105             }
106              
107             sub kill {
108 1     1 0 16142 my ($self, $sig) = @_;
109 1         120 return CORE::kill($sig, $self->pid);
110             }
111              
112             around pgrp => sub {
113             my ($orig, $self, $pgrp) = @_;
114             return $orig->($self) if @_ == 2;
115              
116             setpgrp($self->pid, $pgrp);
117             $self->_set_pgrp($pgrp);
118             };
119              
120             around priority => sub {
121             my ($orig, $self, $pri) = @_;
122             return $orig->($self) if @_ == 2;
123              
124             setpriority(0, $self->pid, $pri);
125             $self->_set_priority($pri);
126             };
127              
128             42;