blib/lib/Proc/ProcessTable/Process.pm

filter: Statementstmt 68.8% 31 / 45 Branchbran 25.0% 4 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 70.0% 7 / 10 Podpod 100% 3 / 3 totaltotal 60.8% 45 / 74 CC 9 SCAR 17.2
CC
9
Cov
57%
priority
12.0
pgrp
12.0
AUTOLOAD
4.6
CRAP 5.6
« blib/lib/Proc/ProcessTable.pm ↑ Summary blib/lib/Proc/Killfam.pm »
1 package Proc::ProcessTable::Process;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 require Exporter;
8 6 require AutoLoader;
9  
10 6 @ISA = qw(Exporter AutoLoader);
11 # Items to export into callers namespace by default. Note: do not export
12 # names by default without a very good reason. Use EXPORT_OK instead.
13 # Do not simply export all your public functions/methods/constants.
14 6 @EXPORT = qw(
15
16 );
17 6 $VERSION = '0.02';
18  
19  
20 # Preloaded methods go here.
21 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 6 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 30 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=4 SCAR=15.2
25 30 my $self = shift;
26 30 ▶ my $type = ref($self)
Branch: 1 branch
BranchTrueFalseTotal
my $type = ref $self or croak("$self is not an object") 30 0 30
27 or croak "$self is not an object";
28
29 30 my $name = $AUTOLOAD;
30 30 $name =~ s/.*://; # strip fully-qualified portion
31
32 30 ▶ unless (exists $self->{$name} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{$name}) 0 30 30
33 0 croak "Can't access `$name' field in class $type";
34 }
35
36 30 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 30 30
37 0 return $self->{$name} = shift;
38 } else {
39 30 return $self->{$name};
40 }
41 }
42  
43 ########################################################
44 # Kill; just a wrapper for perl's kill at the moment
45 ########################################################
46 1 ▶sub kill {
Subroutine kill: called CC=2 SCAR=7.1
Pod documented
47 1 my ($self, $signal) = @_;
48 1 ▶ die "PID " . $self->pid . " not valid." unless($self->pid =~ /^-?\d+$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->pid =~ /^-?\d+$/ 0 1 1
49 1 return( kill($signal, $self->pid) );
50 }
51  
52 ########################################################
53 # Get/set accessors for priority and process group
54 # (everything else is just a get, so handled by autoload)
55 #########################################################
56  
57 # Hmmm... These could use the perl functions to get if not stored on the object
58 0 ▶sub priority {
Subroutine priority: not called CC=3 SCAR=24.8
Pod documented
59 0 my ($self, $priority) = @_;
60 0 ▶ if( defined($priority) ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $priority) 0 0 0
61 0 setpriority(0, $self->pid, $priority);
62 0 ▶ if( getpriority(0, $self->pid) == $priority ){ # Yuck; getpriority doesn't return a status
Branch: 1 branch
BranchTrueFalseTotal
if (getpriority(0, $self->pid) == $priority) 0 0 0
63 0 $self->{priority} = $priority;
64 }
65 }
66 0 return $self->{priority};
67 }
68  
69 0 ▶sub pgrp {
Subroutine pgrp: not called CC=3 SCAR=24.8
Pod documented
70 0 my ($self, $pgrp) = @_;
71 0 ▶ if( defined($pgrp) ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pgrp) 0 0 0
72 0 setpgrp($self->pid, $pgrp);
73 0 ▶ if( getpgrp($self->pid) == $pgrp ){ # Ditto setpgrp
Branch: 1 branch
BranchTrueFalseTotal
if (getpgrp $self->pid == $pgrp) 0 0 0
74 0 $self->{pgrp} = $pgrp;
75 }
76 }
77 0 return $self->{pgrp};
78 }
79  
80  
81 # Apparently needed for mod_perl
82 0 ▶sub DESTROY {}
Subroutine DESTROY: not called CC=1 SCAR=0.0
83  
84 # Autoload methods go after =cut, and are processed by the autosplit program.
85  
86 6 1;
87 __END__
« blib/lib/Proc/ProcessTable.pm ↑ Summary blib/lib/Proc/Killfam.pm »