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