Match/Priority.pm

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