File Coverage

blib/lib/Proc/ProcessTable/Process.pm
Criterion Covered Total %
statement 25 39 64.1
branch 4 16 25.0
condition n/a
subroutine 7 10 70.0
pod 3 3 100.0
total 39 68 57.3


line stmt bran cond sub pod time code
1             package Proc::ProcessTable::Process;
2              
3 6     6   42 use strict;
  6         15  
  6         167  
4 6     6   29 use warnings;
  6         18  
  6         164  
5 6     6   37 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $AUTOLOAD);
  6         9  
  6         614  
6              
7             require Exporter;
8             require AutoLoader;
9              
10             @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             @EXPORT = qw(
15            
16             );
17             $VERSION = '0.02';
18              
19              
20             # Preloaded methods go here.
21 6     6   50 use Carp;
  6         13  
  6         363  
22 6     6   41 use File::Basename;
  6         19  
  6         3159  
23              
24             sub AUTOLOAD {
25 33     33   13912 my $self = shift;
26 33 50       75 my $type = ref($self)
27             or croak "$self is not an object";
28            
29 33         49 my $name = $AUTOLOAD;
30 33         139 $name =~ s/.*://; # strip fully-qualified portion
31            
32 33 50       83 unless (exists $self->{$name} ) {
33 0         0 croak "Can't access `$name' field in class $type";
34             }
35            
36 33 50       69 if (@_) {
37 0         0 return $self->{$name} = shift;
38             } else {
39 33         148 return $self->{$name};
40             }
41             }
42              
43             ########################################################
44             # Kill; just a wrapper for perl's kill at the moment
45             ########################################################
46             sub kill {
47 1     1 1 1435 my ($self, $signal) = @_;
48 1 50       16 die "PID " . $self->pid . " not valid." unless($self->pid =~ /^-?\d+$/);
49 1         16 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             sub priority {
59 0     0 1   my ($self, $priority) = @_;
60 0 0         if( defined($priority) ){
61 0           setpriority(0, $self->pid, $priority);
62 0 0         if( getpriority(0, $self->pid) == $priority ){ # Yuck; getpriority doesn't return a status
63 0           $self->{priority} = $priority;
64             }
65             }
66 0           return $self->{priority};
67             }
68              
69             sub pgrp {
70 0     0 1   my ($self, $pgrp) = @_;
71 0 0         if( defined($pgrp) ){
72 0           setpgrp($self->pid, $pgrp);
73 0 0         if( getpgrp($self->pid) == $pgrp ){ # Ditto setpgrp
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 {}
83              
84             # Autoload methods go after =cut, and are processed by the autosplit program.
85              
86             1;
87             __END__