Match/Username.pm untested

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