| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Net::Connection::Match::Username; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 2 |  |  | 2 |  | 244241 | use 5.006; | 
|  | 2 |  |  |  |  | 55 |  | 
| 4 | 2 |  |  | 2 |  | 14 | use strict; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 52 |  | 
| 5 | 2 |  |  | 2 |  | 10 | use warnings; | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 637 |  | 
| 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 | 2 |  |  | 2 | 1 | 927 | my %args; | 
| 75 | 2 | 100 |  |  |  | 9 | if(defined($_[1])){ | 
| 76 | 1 |  |  |  |  | 3 | %args= %{$_[1]}; | 
|  | 1 |  |  |  |  | 5 |  | 
| 77 |  |  |  |  |  |  | }; | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | # run some basic checks to make sure we have the minimum stuff required to work | 
| 80 | 2 | 100 |  |  |  | 9 | if ( ! defined( $args{usernames} ) ){ | 
| 81 | 1 |  |  |  |  | 10 | die ('No usernames key specified in the argument hash'); | 
| 82 |  |  |  |  |  |  | } | 
| 83 | 1 | 50 |  |  |  | 6 | if ( ref( \$args{usernames} ) eq 'ARRAY' ){ | 
| 84 | 0 |  |  |  |  | 0 | die ('The usernames key is not a array'); | 
| 85 |  |  |  |  |  |  | } | 
| 86 | 1 | 50 |  |  |  | 4 | if ( ! defined $args{usernames}[0] ){ | 
| 87 | 0 |  |  |  |  | 0 | die ('No states defined in the protos array'); | 
| 88 |  |  |  |  |  |  | } | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | my $self = { | 
| 91 |  |  |  |  |  |  | usernames=>$args{usernames}, | 
| 92 | 1 |  |  |  |  | 3 | }; | 
| 93 | 1 |  |  |  |  | 3 | bless $self; | 
| 94 |  |  |  |  |  |  |  | 
| 95 | 1 |  |  |  |  | 4 | 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 | 4 |  |  | 4 | 1 | 3152 | my $self=$_[0]; | 
| 114 | 4 |  |  |  |  | 8 | my $object=$_[1]; | 
| 115 |  |  |  |  |  |  |  | 
| 116 | 4 | 100 |  |  |  | 14 | if ( !defined( $object ) ){ | 
| 117 | 1 |  |  |  |  | 3 | return 0; | 
| 118 |  |  |  |  |  |  | } | 
| 119 |  |  |  |  |  |  |  | 
| 120 | 3 | 100 |  |  |  | 12 | if ( ref( $object ) ne 'Net::Connection' ){ | 
| 121 | 1 |  |  |  |  | 4 | return 0; | 
| 122 |  |  |  |  |  |  | } | 
| 123 |  |  |  |  |  |  |  | 
| 124 |  |  |  |  |  |  | # does not have a user.... we won't match | 
| 125 | 2 | 50 |  |  |  | 6 | if ( ! defined( $object->username ) ){ | 
| 126 | 0 |  |  |  |  | 0 | return 0; | 
| 127 |  |  |  |  |  |  | } | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | # check for matches | 
| 130 | 2 |  |  |  |  | 15 | foreach my $username ( @{ $self->{usernames} } ){ | 
|  | 2 |  |  |  |  | 8 |  | 
| 131 | 3 | 100 |  |  |  | 9 | if ( $username eq $object->username ){ | 
| 132 | 1 |  |  |  |  | 9 | return 1; | 
| 133 |  |  |  |  |  |  | } | 
| 134 |  |  |  |  |  |  | } | 
| 135 |  |  |  |  |  |  |  | 
| 136 | 1 |  |  |  |  | 7 | return 0; | 
| 137 |  |  |  |  |  |  | } | 
| 138 |  |  |  |  |  |  |  | 
| 139 |  |  |  |  |  |  | =head1 AUTHOR | 
| 140 |  |  |  |  |  |  |  | 
| 141 |  |  |  |  |  |  | Zane C. Bowers-Hadley, C<<  >> | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | =head1 BUGS | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | Please report any bugs or feature requests to C, or through | 
| 146 |  |  |  |  |  |  | the web interface at L.  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 | 
| 166 |  |  |  |  |  |  |  | 
| 167 |  |  |  |  |  |  | =item * AnnoCPAN: Annotated CPAN documentation | 
| 168 |  |  |  |  |  |  |  | 
| 169 |  |  |  |  |  |  | L | 
| 170 |  |  |  |  |  |  |  | 
| 171 |  |  |  |  |  |  | =item * CPAN Ratings | 
| 172 |  |  |  |  |  |  |  | 
| 173 |  |  |  |  |  |  | L | 
| 174 |  |  |  |  |  |  |  | 
| 175 |  |  |  |  |  |  | =item * Search CPAN | 
| 176 |  |  |  |  |  |  |  | 
| 177 |  |  |  |  |  |  | L | 
| 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 | 
| 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 |