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