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