Match/Time.pm

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