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