Match/PID.pm

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