Process/Probe.pm

filter: Statementstmt 93.6% 59 / 63 Branchbran 64.2% 9 / 14 Conditioncond 50.0% 3 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 14 / 14 Podpod 40.0% 2 / 5 totaltotal 83.9% 89 / 106 CC 12 SCAR 10.3
CC
12
Cov
86%
run
5.0
unavailable
4.7
new
3.0
CRAP 2.8
« Process/Delegatable.pm ↑ Summary Process/Packageable.pm »
1 package Process::Probe;
2  
3 =pod
4  
5 =head1 NAME
6  
7 Process::Probe - Process to test if any named classes are installed
8  
9 =head1 SYNOPSIS
10  
11 my $probe = Process::Probe->new( qw{
12 My::Process
13 CPAN::Module::Process
14 Something::Else
15 } );
16
17 $probe->run;
18
19 # Lists of classes
20 my @yep = $probe->available;
21 my @nope = $probe->unavailable;
22 my @maybe = $probe->unknown;
23
24 # Test for single class with any of the above
25 if ( $probe->available('My::Process') ) {
26 print "My::Process is available\n";
27 }
28  
29 =head1 DESCRIPTION
30  
31 B<Process::Probe> is a simple and standardised class available that is
32 available with the core L<Process> distribution. It is used to probe
33 a host to determine whether or not the remote host has certain process
34 classes installed.
35  
36 By default, the object will search through the system's include path to
37 find the .pm files that match the particular classes.
38  
39 Typical examples of using the default functionality could include
40 executing a B<Process::Probe> object via a SSH login on a remote host
41 to determine which of a set of desired classes exist on the remote host.
42  
43 The probe will ONLY check for the existance of classes that are in the
44 unknown state at the time the C<run> method is called.
45  
46 In scenarios where the requestor does not have direct execution rights
47 on the remote host, and the request is being marshalled via a server
48 process, this allows security code on the server to preset forbidden
49 classes to no before the probe is run, or to otherwise manipulate the
50 "answer" to the "question" that B<Process::Probe> represents.
51  
52 No functionality is provided to query ALL the C<Process>-compatible
53 classes on a remote host. This is intentional. It prevents very
54 disk-intensive scans, protects remote host against hostile requests,
55 and prevents the use of these objects en-mass as a denial of service.
56  
57 =cut
58  
59 3 ▶use 5.00503;
Subroutine BEGIN: called CC=1 SCAR=0.0
60 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
61 3 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
62 3 ▶use List::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
63 3 ▶use Params::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
64 3 ▶use Process::Delegatable ();
Subroutine BEGIN: called CC=1 SCAR=0.0
65 3 ▶use Process ();
Subroutine BEGIN: called CC=1 SCAR=0.0
66  
67 3 ▶use vars qw{$VERSION @ISA};
Subroutine BEGIN: called CC=1 SCAR=0.0
68 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
69 3 $VERSION = '0.30';
70 3 @ISA = qw{
71 Process::Delegatable
72 Process
73 };
74 }
75  
76 2 ▶sub new {
Subroutine new: called CC=3 SCAR=11.1
Pod documented
77 2 my $class = shift;
78  
79 # Create the object
80 2 my $self = bless {
81 modules => { },
82 }, $class;
83  
84 # Add the modules to test for
85 2 ▶ while ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 6 2 8
86 6 my $module = shift;
87 6 ▶ unless ( Params::Util::_CLASS($module) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&Params::Util::_CLASS($module)) 0 6 6
88 0 return undef;
89 }
90 6 $self->{modules}->{$module} = undef;
91 }
92  
93 2 return $self;
94 }
95  
96 2 ▶sub run {
Subroutine run: called CC=5 SCAR=16.1
Pod documented
97 2 my $self = shift;
98 2 my $hash = $self->{modules};
99 2 foreach my $key ( sort keys %$hash ) {
100 6 $hash->{$key} = 0;
101 6 my @path = split /::/, $key;
102 6 foreach my $dir ( @INC ) {
103 44 ▶ next if ref $dir;
Branch: 1 branch
BranchTrueFalseTotal
if ref $dir 0 44 44
104 44 ▶ next unless -f File::Spec->catfile($dir, @path) . '.pm';
Branch: 1 branch
BranchTrueFalseTotal
unless -f "File::Spec"->catfile($dir, @path) . '.pm' 40 4 44
105 4 $hash->{$key} = 1;
106 4 last;
107 }
108 }
109 2 return 1;
110 }
111  
112 3 ▶sub available {
Subroutine available: called CC=2 SCAR=7.2
Pod undocumented
113 3 my $self = shift;
114 3 my $hash = $self->{modules};
115 3 ▶ if ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 3 3
116 return !! (
117 0 $hash->{$_[0]}
118 );
119 } else {
120 return grep {
121 3 $hash->{$_}
122 } sort keys %$hash;
123 }
124 }
125  
126 3 ▶sub unavailable {
Subroutine unavailable: called CC=4 SCAR=15.5
Pod undocumented
127 3 my $self = shift;
128 3 my $hash = $self->{modules};
129 3 ▶ if ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 3 3
130 return !! (
131 defined $hash->{$_[0]}
132 and
133 0 ▶ not $hash->{$_[0]}
Condition0%0/3
defined $$hash{$_[0]} && !$$hash{$_[0]}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $$hash{$_[0]} && !$$hash{$_[0]}
defined $$hash{$_[0]} !$$hash{$_[0]}
Truth table0%0/3
A && not(B)
A= defined $$hash{$_[0]}B= !$$hash{$_[0]}
ABresult
0X0
100
111
134 );
135 } else {
136 return grep {
137 3 ▶ defined $hash->{$_} and not $hash->{$_}
Condition100%3/3
defined $hash->{$_} && !$hash->{$_}
!ll&&!rl&&r
342
MC/DC100%2/2
defined $hash->{$_} && !$hash->{$_}
defined $hash->{$_} !$hash->{$_}
Truth table100%3/3
A && not(B)
A= defined $hash->{$_}B= !$hash->{$_}
ABresult
0X0
100
111
138 } sort keys %$hash;
139 }
140 }
141  
142 3 ▶sub unknown {
Subroutine unknown: called CC=2 SCAR=7.2
Pod undocumented
143 3 my $self = shift;
144 3 my $hash = $self->{modules};
145 3 ▶ if ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 3 3
146 return !! (
147 0 not defined $hash->{$_[0]}
148 );
149 } else {
150 return grep {
151 3 not defined $hash->{$_}
152 } sort keys %$hash;
153 }
154 }
155  
156 3 1;
157  
158 =pod
159  
160 =head1 SUPPORT
161  
162 Bugs should be reported via the CPAN bug tracker at
163  
164 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Process>
165  
166 For other issues, contact the author.
167  
168 =head1 AUTHOR
169  
170 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
171  
172 =head1 SEE ALSO
173  
174 L<http://ali.as/>
175  
176 =head1 COPYRIGHT
177  
178 Copyright 2006 - 2011 Adam Kennedy.
179  
180 This program is free software; you can redistribute
181 it and/or modify it under the same terms as Perl itself.
182  
183 The full text of the license can be found in the
184 LICENSE file included with this module.
185  
186 =cut
« Process/Delegatable.pm ↑ Summary Process/Packageable.pm »