Match/WChan.pm

filter: Statementstmt 100% 46 / 46 Branchbran 100% 20 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 2 / 2 totaltotal 100% 73 / 73 CC 12 SCAR 17.0
CC
12
Cov
100%
new
7.0
match
6.0
BEGIN
1.0
CRAP 5.5
« Match/State.pm ↑ Summary Match/EGIDset.pm »
1 package Proc::ProcessTable::Match::WChan;
2  
3 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 NAME
8  
9 Proc::ProcessTable::Match::WChan - Check if the wait channel of a process matches via regexp.
10  
11 =head1 VERSION
12  
13 Version 0.1.0
14  
15 =cut
16  
17 2 our $VERSION = '0.1.0';
18  
19  
20 =head1 SYNOPSIS
21  
22 use Proc::ProcessTable::Match::WChan;
23
24 my %args=(
25 wchans=>[
26 'select',
27 ],
28 );
29
30 my $checker=Proc::ProcessTable::Match::WChan->new( \%args );
31
32 if ( $checker->match( $proc ) ){
33 print "It matches.\n";
34 }
35  
36 =head1 METHODS
37  
38 =head2 new
39  
40 This intiates the object.
41  
42 It takes a hash reference with one key. One key is required and
43 that is 'wchans', which is a array of wait channels to match.
44  
45 The matching is done via regexp.
46  
47 Atleast one wchan must be specified.
48  
49 If the new method fails, it dies.
50  
51 my %args=(
52 wchans=>[
53 'select',
54 ],
55 );
56
57 my $checker=Proc::ProcessTable::Match::WChan->new( \%args );
58  
59 =cut
60  
61 8 ▶sub new{
Subroutine new: called CC=7 SCAR=19.5
Pod documented
62 8 my %args;
63 8 ▶ if(defined($_[1])){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) 7 1 8
64 7 %args= %{$_[1]};
65 };
66  
67 # run some basic checks to make sure we have the minimum stuff required to work
68 8 ▶ if ( ! defined( $args{wchans} ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"wchans"}) 2 6 8
69 2 die ('No wchans key specified in the argument hash');
70 }
71 6 ▶ if ( ref( $args{wchans} ) ne 'ARRAY' ){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"wchans"} ne "ARRAY") 1 5 6
72 1 die ('The wchans key is not a array');
73 }
74 5 ▶ if ( ! defined $args{wchans}[0] ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"wchans"}[0]) 1 4 5
75 1 die ('Nothing defined in the wchans array');
76 }
77  
78 # make sure each specified value compiles as a regex
79 4 my $regex_int=0;
80 4 ▶ while ( defined( $args{wchans}[$regex_int] ) ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"wchans"}[$regex_int]) 5 3 8
81 5 ▶ if ( ! eval{ qr/$args{wchans}[$regex_int]/ } ){
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { qr/$args{"wchans"}[$regex_int]/ } }) 1 4 5
82 1 die (q{The value "}.$args{wchans}[$regex_int].q{" in the wchans array does not compile as a regex... }.$@);
83 }
84 4 $regex_int++;
85 }
86  
87 3 my $class=$_[0];
88 my $self = {
89 wchans=>$args{wchans},
90 3 };
91 3 bless $self, $class;
92  
93 3 return $self;
94 }
95  
96 =head2 match
97  
98 Checks if a single Proc::ProcessTable::Process object matches the stack.
99  
100 One argument is taken and that is a Proc::ProcessTable::Process object.
101  
102 The returned value is a boolean.
103  
104 if ( $checker->match( $proc ) ){
105 print "The process matches.\n";
106 }
107  
108 =cut
109  
110 6 ▶sub match{
Subroutine match: called CC=6 SCAR=17.9
Pod documented
111 6 my $self=$_[0];
112 6 my $object=$_[1];
113  
114 6 ▶ if ( !defined( $object ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $object) 1 5 6
115 1 return 0;
116 }
117  
118 5 ▶ if ( ref( $object ) ne 'Proc::ProcessTable::Process' ){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $object ne "Proc::ProcessTable::Process") 1 4 5
119 1 return 0;
120 }
121  
122 4 my $proc_wchan;
123 4 eval{
124 4 $proc_wchan=$object->wchan;
125 };
126  
127 # don't bother proceeding, the object won't match ever
128 # as it does not have a wchan
129 4 ▶ if ( ! defined( $proc_wchan ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $proc_wchan) 1 3 4
130 1 return 0;
131 }
132  
133 3 foreach my $wchan ( @{ $self->{wchans} } ){
134 4 ▶ if ( $proc_wchan =~ /$wchan/ ){
Branch: 1 branch
BranchTrueFalseTotal
if ($proc_wchan =~ /$wchan/) 2 2 4
135 2 return 1;
136 }
137 }
138  
139 1 return 0;
140 }
141  
142 =head1 AUTHOR
143  
144 Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
145  
146 =head1 BUGS
147  
148 Please report any bugs or feature requests to C<bug-Proc-ProcessTable-Match at rt.cpan.org>, or through
149 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Proc-ProcessTable-Match>. I will be notified, and then you'll
150 automatically be notified of progress on your bug as I make changes.
151  
152  
153  
154  
155 =head1 SUPPORT
156  
157 You can find documentation for this module with the perldoc command.
158  
159 perldoc Proc::ProcessTable::Match
160  
161  
162 You can also look for information at:
163  
164 =over 4
165  
166 =item * RT: CPAN's request tracker (report bugs here)
167  
168 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Proc-ProcessTable-Match>
169  
170 =item * Search CPAN
171  
172 L<https://metacpan.org/release/Proc-ProcessTable-Match>
173  
174 =back
175  
176  
177 =head1 ACKNOWLEDGEMENTS
178  
179  
180 =head1 LICENSE AND COPYRIGHT
181  
182 Copyright 2019 Zane C. Bowers-Hadley.
183  
184 This program is free software; you can redistribute it and/or modify it
185 under the terms of the the Artistic License (2.0). You may obtain a
186 copy of the full license at:
187  
188 L<http://www.perlfoundation.org/artistic_license_2_0>
189  
190 Any use, modification, and distribution of the Standard or Modified
191 Versions is governed by this Artistic License. By using, modifying or
192 distributing the Package, you accept this license. Do not use, modify,
193 or distribute the Package, if you do not accept this license.
194  
195 If your Modified Version has been derived from a Modified Version made
196 by someone other than you, you are nevertheless required to ensure that
197 your Modified Version complies with the requirements of this license.
198  
199 This license does not grant you the right to use any trademark, service
200 mark, tradename, or logo of the Copyright Holder.
201  
202 This license includes the non-exclusive, worldwide, free-of-charge
203 patent license to make, have made, use, offer to sell, sell, import and
204 otherwise transfer the Package with respect to any patent claims
205 licensable by the Copyright Holder that are necessarily infringed by the
206 Package. If you institute patent litigation (including a cross-claim or
207 counterclaim) against any party alleging that the Package constitutes
208 direct or contributory patent infringement, then this Artistic License
209 to you shall terminate on the date that such litigation is filed.
210  
211 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
212 AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
213 THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
214 PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
215 YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
216 CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
217 CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
218 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
219  
220  
221 =cut
222  
223 2 1; # End of Proc::ProcessTable::Match
« Match/State.pm ↑ Summary Match/EGIDset.pm »