blib/lib/Proc/ProcessTable.pm

filter: Statementstmt 64.7% 57 / 88 Branchbran 30.0% 9 / 30 Conditioncond 38.8% 7 / 18 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 85.7% 12 / 14 Podpod 50.0% 1 / 2 totaltotal 53.0% 86 / 162 CC 22 SCAR 24.0
CC
22
Cov
54%
initialize
21.2
AUTOLOAD
20.0
new
14.7
CRAP 11.0
« blib/lib/Proc/Killall.pm ↑ Summary blib/lib/Proc/ProcessTable/Process.pm »
1 package Proc::ProcessTable;
2  
3 6 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 6 require Exporter;
12 6 require DynaLoader;
13  
14 6 @ISA = qw(Exporter DynaLoader);
15 # Items to export into callers namespace by default. Note: do not export
16 # names by default without a very good reason. Use EXPORT_OK instead.
17 # Do not simply export all your public functions/methods/constants.
18 6 @EXPORT = qw(
19
20 );
21 6 $VERSION = '0.637';
22  
23 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=4 SCAR=30.0
24 # This AUTOLOAD is used to 'autoload' constants from the constant()
25 # XS function. If a constant is not found then control is passed
26 # to the AUTOLOAD in AutoLoader.
27  
28 0 my $constname;
29 0 ($constname = $AUTOLOAD) =~ s/.*:://;
30 0 ▶ my $val = constant($constname, @_ ? $_[0] : 0);
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
31 0 ▶ if ($! != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($! != 0) 0 0 0
32 0 ▶ if ($! =~ /Invalid/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($! =~ /Invalid/) { } 0 0 0
33 0 $AutoLoader::AUTOLOAD = $AUTOLOAD;
34 0 goto &AutoLoader::AUTOLOAD;
35 }
36 else {
37 0 croak "Your vendor has not defined Proc::ProcessTable macro $constname";
38 }
39 }
40 0 eval "sub $AUTOLOAD { $val }";
41 0 goto &$AUTOLOAD;
42 }
43  
44 6 bootstrap Proc::ProcessTable $VERSION;
45  
46 # Preloaded methods go here.
47 6 ▶use Proc::ProcessTable::Process;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 6 ▶use File::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50 6 my %TTYDEVS;
51  
52 6 our $TTYDEVSFILE = "/tmp/TTYDEVS_" . $Config{byteorder}; # Where we store the TTYDEVS hash
53  
54 sub new
55 3 ▶{
Subroutine new: called CC=8 SCAR=26.9
Pod documented
56 3 my ($this, %args) = @_;
57 3 ▶ my $class = ref($this) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
030
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
58 3 my $self = {};
59 3 bless $self, $class;
60  
61 3 mutex_new(1);
62 3 ▶ if ( exists $args{cache_ttys} && $args{cache_ttys} == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"cache_ttys"} and $args{"cache_ttys"} == 1) 0 3 3
Condition33%1/3
exists $args{"cache_ttys"} and $args{"cache_ttys"} == 1
!ll&&!rl&&r
300
MC/DC0%0/2
exists $args{"cache_ttys"} and $args{"cache_ttys"} == 1
exists $args{"cache_ttys"} $args{"cache_ttys"} == 1
Truth table33%1/3
A and B
A= exists $args{"cache_ttys"}B= $args{"cache_ttys"} == 1
ABresult
0X0
100
111
63 {
64 0 $self->{cache_ttys} = 1
65 }
66  
67 3 ▶ if ( exists $args{enable_ttys} && (! $args{enable_ttys}))
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'enable_ttys'} and not $args{'enable_ttys'}) { } 0 3 3
Condition33%1/3
exists $args{"enable_ttys"} and not $args{"enable_ttys"}
!ll&&!rl&&r
300
MC/DC0%0/2
exists $args{"enable_ttys"} and not $args{"enable_ttys"}
exists $args{"enable_ttys"} not $args{"enable_ttys"}
Truth table33%1/3
A and not(B)
A= exists $args{"enable_ttys"}B= not $args{"enable_ttys"}
ABresult
0X0
100
111
68 {
69 0 $self->{enable_ttys} = 0;
70 0 ▶ if ($self->{'cache_ttys'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"cache_ttys"}) 0 0 0
71 0 carp("cache_ttys specified with enable_ttys, cache_ttys a no-op");
72 }
73 }
74 else
75 {
76 3 $self->{enable_ttys} = 1;
77 }
78  
79 3 my $status = $self->initialize;
80 3 mutex_new(0);
81 3 ▶ if($status)
Branch: 1 branch
BranchTrueFalseTotal
if ($status) { } 3 0 3
82 {
83 3 return $self;
84 }
85 else
86 {
87 0 return undef;
88 }
89 }
90  
91 sub initialize
92 3 ▶{
Subroutine initialize: called CC=6 SCAR=30.5
Pod undocumented
93 3 my ($self) = @_;
94  
95 3 ▶ if ($self->{enable_ttys})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"enable_ttys"}) 3 0 3
96 {
97  
98 # Get the mapping of TTYs to device nums
99 # reading/writing the cache if we are caching
100 3 ▶ if( $self->{cache_ttys} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'cache_ttys'}) { } 0 3 3
101 {
102  
103 0 require Storable;
104  
105 0 ▶ if( -r $TTYDEVSFILE )
Branch: 1 branch
BranchTrueFalseTotal
if (-r $Proc::ProcessTable::TTYDEVSFILE) { } 0 0 0
106 {
107 0 $_ = Storable::retrieve($TTYDEVSFILE);
108 0 %Proc::ProcessTable::TTYDEVS = %$_;
109 }
110 else
111 {
112 0 $self->_get_tty_list;
113  
114 0 require File::Temp;
115 0 require File::Basename;
116  
117 0 my($ttydevs_fh, $ttydevs_tmpfile) = File::Temp::tempfile('ProcessTable_XXXXXXXX', DIR => File::Basename::dirname($TTYDEVSFILE));
118 0 chmod 0644, $ttydevs_tmpfile;
119 0 Storable::store_fd( \%Proc::ProcessTable::TTYDEVS, $ttydevs_fh );
120 0 close $ttydevs_fh;
121  
122 0 ▶ if( !rename $ttydevs_tmpfile, $TTYDEVSFILE )
Branch: 1 branch
BranchTrueFalseTotal
unless (rename $ttydevs_tmpfile, $Proc::ProcessTable::TTYDEVSFILE) 0 0 0
123 {
124 0 my $err = $!;
125 0 unlink $ttydevs_tmpfile;
126 0 ▶ if( !-r $TTYDEVSFILE)
Branch: 1 branch
BranchTrueFalseTotal
unless (-r $Proc::ProcessTable::TTYDEVSFILE) 0 0 0
127 {
128 0 die "Renaming $ttydevs_tmpfile to $TTYDEVSFILE failed: $err";
129 }
130 # else somebody else obviously created the file in the meantime
131 }
132 }
133 }
134 else
135 {
136 3 $self->_get_tty_list;
137 }
138 }
139  
140 # Call the os-specific initialization
141 3 $self->_initialize_os;
142  
143 3 return 1;
144 }
145  
146 ###############################################
147 # Generate a hash mapping TTY numbers to paths.
148 # This might be faster in Table.xs,
149 # but it's a lot more portable here
150 ###############################################
151 sub _get_tty_list
152 3 ▶{
Subroutine _get_tty_list: called CC=2 SCAR=7.6
153 3 my ($self) = @_;
154 3 undef %Proc::ProcessTable::TTYDEVS;
155 3 ▶ return unless -d "/dev";
Branch: 1 branch
BranchTrueFalseTotal
unless -d "/dev" 0 3 3
156 find({ wanted =>
157 51 ▶ sub{
Subroutine __ANON__: called CC=6 SCAR=20.7
158 51 ▶ $File::Find::prune = 1 if -d $_ && ( ! -x $_ || $_ eq "/dev/.lxc" || $_ eq "/dev/.lxd-mounts");
Branch: 1 branch
BranchTrueFalseTotal
if -d $_ and !(-x $_) || $_ eq "/dev/.lxc" || $_ eq "/dev/.lxd-mounts" 0 51 51
Condition44%4/9
-d $_ and !(-x $_) || $_ eq "/dev/.lxc" || $_ eq "/dev/.lxd-mounts"
!ll&&!rl&&r
36150
not -x $_ or $_ eq "/dev/.lxc" or $_ eq "/dev/.lxd-mounts"
l!l&&r!l&&!r
0015
not -x $_ or $_ eq "/dev/.lxc"
l!l&&r!l&&!r
0015
MC/DC0%0/4
-d $_ and !(-x $_) || $_ eq "/dev/.lxc" || $_ eq "/dev/.lxd-mounts"
-d $_ not -x $_ $_ eq "/dev/.lxc" $_ eq "/dev/.lxd-mounts"
Truth table40%2/5
A and not(B) or C or D
A= -d $_B= not -x $_C= $_ eq "/dev/.lxc"D= $_ eq "/dev/.lxd-mounts"
ABCDresult
0XXX0
10000
11XX1
101X1
10011
159 51 my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
160 $atime,$mtime,$ctime,$blksize,$blocks) = stat($File::Find::name);
161 51 ▶ $Proc::ProcessTable::TTYDEVS{$rdev} = $File::Find::name
Branch: 1 branch
BranchTrueFalseTotal
if -c $File::Find::name 30 21 51
162 if(-c $File::Find::name);
163 3 }, no_chdir => 1},
164 "/dev"
165 );
166 }
167  
168 # Apparently needed for mod_perl
169 0 ▶sub DESTROY {}
Subroutine DESTROY: not called CC=1 SCAR=0.0
170  
171 6 1;
172 __END__
« blib/lib/Proc/Killall.pm ↑ Summary blib/lib/Proc/ProcessTable/Process.pm »