| 1 | package Net::Connection::Sort::host_lf; | ||||||||||||||||||||||||||||||||||||||||||
| 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 | 2 | ▶ | use Net::IP; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | Net::Connection::Sort::host_lf - Sorts the connections via the local host and then foreign host. | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | Version 0.0.0 | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | our $VERSION = '0.0.0'; | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | use Net::Connection::Sort::host_fl; | ||||||||||||||||||||||||||||||||||||||||||
| 24 | use Net::Connection; | ||||||||||||||||||||||||||||||||||||||||||
| 25 | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | my @objects=( | ||||||||||||||||||||||||||||||||||||||||||
| 28 | Net::Connection->new({ | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 'foreign_host' => '3.3.3.4', | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 'local_host' => '4.4.4.5', | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 'foreign_port' => '22', | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 'local_port' => '11132', | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 'sendq' => '1', | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 'recvq' => '0', | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 'state' => 'ESTABLISHED', | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 'proto' => 'tcp4' | ||||||||||||||||||||||||||||||||||||||||||
| 37 | }), | ||||||||||||||||||||||||||||||||||||||||||
| 38 | Net::Connection->new({ | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 'foreign_host' => '1.1.1.1', | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 'local_host' => '2.2.2.2', | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 'foreign_port' => '22', | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 'local_port' => '11132', | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 'sendq' => '1', | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 'recvq' => '0', | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 'state' => 'ESTABLISHED', | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 'proto' => 'tcp4' | ||||||||||||||||||||||||||||||||||||||||||
| 47 | }), | ||||||||||||||||||||||||||||||||||||||||||
| 48 | Net::Connection->new({ | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 'foreign_host' => '5.5.5.5', | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 'local_host' => '6.6.6.6', | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 'foreign_port' => '22', | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 'local_port' => '11132', | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 'sendq' => '1', | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 'recvq' => '0', | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 'state' => 'ESTABLISHED', | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 'proto' => 'tcp4' | ||||||||||||||||||||||||||||||||||||||||||
| 57 | }), | ||||||||||||||||||||||||||||||||||||||||||
| 58 | Net::Connection->new({ | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 'foreign_host' => '3.3.3.3', | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 'local_host' => '4.4.4.4', | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 'foreign_port' => '22', | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 'local_port' => '11132', | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 'sendq' => '1', | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 'recvq' => '0', | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 'state' => 'ESTABLISHED', | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 'proto' => 'tcp4' | ||||||||||||||||||||||||||||||||||||||||||
| 67 | }), | ||||||||||||||||||||||||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | my $sorter=$sorter=Net::Connection::Sort::host_lf->new; | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | @objects=$sorter->sorter( \@objects ); | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | print Dumper( \@objects ); | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | =head2 new | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | This initiates the module. | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | No arguments are taken and this will always succeed. | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | my $sorter=$sorter=Net::Connection::Sort::host_lf->new; | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | sub new{ | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | ▶ | my %args; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | ▶ | if(defined($_[1])){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | %args= %{$_[1]}; | |||||||||||||||||||||||||||||||||||||||||
| 92 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | my $self = { | |||||||||||||||||||||||||||||||||||||||||
| 96 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | bless $self; | |||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | =head2 sort | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | This sorts the array of Net::Connection objects. | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | One object is taken and that is a array of objects. | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | @objects=$sorter->sorter( \@objects ); | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | print Dumper( \@objects ); | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | sub sorter{ | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | ▶ | my $self=$_[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sorter: called CC=4 SCAR=14.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 1 | my @objects; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $_[1] and ref $_[1] eq "ARRAY"
MC/DC0%0/2
defined $_[1] and ref $_[1] eq "ARRAY"
defined $_[1]
ref $_[1] eq "ARRAY"
Truth table33%1/3
A and B
A= defined $_[1]B= ref $_[1] eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | defined( $_[1] ) && | ||||||||||||||||||||||||||||||||||||||||||
| 119 | ( ref($_[1]) eq 'ARRAY' ) | ||||||||||||||||||||||||||||||||||||||||||
| 120 | ){ | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 1 | @objects=@{ $_[1] }; | |||||||||||||||||||||||||||||||||||||||||
| 122 | }else{ | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | die 'The passed item is either not a array or undefined'; | |||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | @objects=sort { | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | &helper( $a->{local_host} ) <=> &helper( $b->{local_host} ) or | |||||||||||||||||||||||||||||||||||||||||
| 128 | &helper( $a->{foreign_host} ) <=> &helper( $b->{foreign_host} ) | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 5 | ▶ | } @objects; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | return @objects; | |||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | =head2 helper | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | This is a internal function. | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | sub helper{ | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 12 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
helper: called CC=5 SCAR=20.3
Pod
documented
Branch: 1 branch
Condition33%2/6
not defined $_[0] or $_[0] eq "*" or $_[0] =~ /[g-zG-Z]/
not defined $_[0] or $_[0] eq "*"
MC/DC0%0/3
not defined $_[0] or $_[0] eq "*" or $_[0] =~ /[g-zG-Z]/
not defined $_[0]
$_[0] eq "*"
$_[0] =~ /[g-zG-Z]/
Truth table25%1/4
not(A) or B or C
A= not defined $_[0]B= $_[0] eq "*"C= $_[0] =~ /[g-zG-Z]/
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | ( !defined($_[0]) ) || | ||||||||||||||||||||||||||||||||||||||||||
| 143 | ( $_[0] eq '*' ) || | ||||||||||||||||||||||||||||||||||||||||||
| 144 | ( $_[0] =~ /[g-zG-Z]/ ) | ||||||||||||||||||||||||||||||||||||||||||
| 145 | ){ | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 12 | my $host=eval { Net::IP->new( $_[0] )->intip} ; | |||||||||||||||||||||||||||||||||||||||||
| 149 | 12 | ▶ | if (!defined( $host )){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 12 | return $host; | |||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >> | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | Please report any bugs or feature requests to C<bug-net-connection-sort at rt.cpan.org>, or through | ||||||||||||||||||||||||||||||||||||||||||
| 162 | the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Connection-Sort>. I will be notified, and then you'll | ||||||||||||||||||||||||||||||||||||||||||
| 163 | automatically be notified of progress on your bug as I make changes. | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | =head1 SUPPORT | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | perldoc Net::Connection::Sort | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | You can also look for information at: | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | =item * RT: CPAN's request tracker (report bugs here) | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Connection-Sort> | ||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | L<http://annocpan.org/dist/Net-Connection-Sort> | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | =item * CPAN Ratings | ||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | L<https://cpanratings.perl.org/d/Net-Connection-Sort> | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | =item * Search CPAN | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | L<https://metacpan.org/release/Net-Connection-Sort> | ||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | =item * Git Repo | ||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | L<https://gitea.eesdp.org/vvelox/Net-Connection-Sort> | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | This software is Copyright (c) 2019 by Zane C. Bowers-Hadley. | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | This is free software, licensed under: | ||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | The Artistic License 2.0 (GPL Compatible) | ||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | 2 | 1; # End of Net::Connection::Sort | |||||||||||||||||||||||||||||||||||||||||