state fully implemented and tests fine
This commit is contained in:
parent
34f1fa633f
commit
a009faf7bc
|
@ -1,4 +1,4 @@
|
|||
package Net::Connection::Sort::host_f;
|
||||
package Net::Connection::Sort::state;
|
||||
|
||||
use 5.006;
|
||||
use strict;
|
||||
|
@ -7,7 +7,7 @@ use Net::IP;
|
|||
|
||||
=head1 NAME
|
||||
|
||||
Net::Connection::Sort::host_f - Sorts the connections via the foreign host.
|
||||
Net::Connection::Sort::state - Sorts the connections via the connection state.
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
|
@ -20,7 +20,7 @@ our $VERSION = '0.0.0';
|
|||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
use Net::Connection::Sort::host_f;
|
||||
use Net::Connection::Sort::state;
|
||||
use Net::Connection;
|
||||
use Data::Dumper;
|
||||
|
||||
|
@ -32,7 +32,7 @@ our $VERSION = '0.0.0';
|
|||
'local_port' => '11132',
|
||||
'sendq' => '1',
|
||||
'recvq' => '0',
|
||||
'state' => 'ESTABLISHED',
|
||||
'state' => 'LISTEN',
|
||||
'proto' => 'tcp4'
|
||||
}),
|
||||
Net::Connection->new({
|
||||
|
@ -42,7 +42,7 @@ our $VERSION = '0.0.0';
|
|||
'local_port' => '11132',
|
||||
'sendq' => '1',
|
||||
'recvq' => '0',
|
||||
'state' => 'ESTABLISHED',
|
||||
'state' => 'FIN_WAIT_2',
|
||||
'proto' => 'tcp4'
|
||||
}),
|
||||
Net::Connection->new({
|
||||
|
@ -52,7 +52,7 @@ our $VERSION = '0.0.0';
|
|||
'local_port' => '11132',
|
||||
'sendq' => '1',
|
||||
'recvq' => '0',
|
||||
'state' => 'ESTABLISHED',
|
||||
'state' => 'TIME_WAIT',
|
||||
'proto' => 'tcp4'
|
||||
}),
|
||||
Net::Connection->new({
|
||||
|
@ -67,7 +67,7 @@ our $VERSION = '0.0.0';
|
|||
}),
|
||||
);
|
||||
|
||||
my $sorter=$sorter=Net::Connection::Sort::host_f->new;
|
||||
my $sorter=$sorter=Net::Connection::Sort::state->new;
|
||||
|
||||
@objects=$sorter->sorter( \@objects );
|
||||
|
||||
|
@ -81,7 +81,7 @@ This initiates the module.
|
|||
|
||||
No arguments are taken and this will always succeed.
|
||||
|
||||
my $sorter=$sorter=Net::Connection::Sort::host_f->new;
|
||||
my $sorter=$sorter=Net::Connection::Sort::state->new;
|
||||
|
||||
=cut
|
||||
|
||||
|
@ -124,33 +124,12 @@ sub sorter{
|
|||
}
|
||||
|
||||
@objects=sort {
|
||||
&helper( $a->foreign_host ) <=> &helper( $b->foreign_host )
|
||||
$a->state cmp $b->state
|
||||
} @objects;
|
||||
|
||||
return @objects;
|
||||
}
|
||||
|
||||
=head2 helper
|
||||
|
||||
This is a internal function.
|
||||
|
||||
=cut
|
||||
|
||||
sub helper{
|
||||
if (
|
||||
( !defined($_[0]) ) ||
|
||||
( $_[0] eq '*' ) ||
|
||||
( $_[0] =~ /[g-zG-Z]/ )
|
||||
){
|
||||
return 0;
|
||||
}
|
||||
my $host=eval { Net::IP->new( $_[0] )->intip} ;
|
||||
if (!defined( $host )){
|
||||
return 0;
|
||||
}
|
||||
return $host;
|
||||
}
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
|
||||
|
|
|
@ -13,7 +13,7 @@ my @objects=(
|
|||
'local_port' => '11132',
|
||||
'sendq' => '1',
|
||||
'recvq' => '0',
|
||||
'state' => 'ESTABLISHED',
|
||||
'state' => 'LISTEN',
|
||||
'proto' => 'tcp4'
|
||||
}),
|
||||
Net::Connection->new({
|
||||
|
@ -23,7 +23,7 @@ my @objects=(
|
|||
'local_port' => '11132',
|
||||
'sendq' => '1',
|
||||
'recvq' => '0',
|
||||
'state' => 'ESTABLISHED',
|
||||
'state' => 'FIN_WAIT_2',
|
||||
'proto' => 'tcp4'
|
||||
}),
|
||||
Net::Connection->new({
|
||||
|
@ -33,7 +33,7 @@ my @objects=(
|
|||
'local_port' => '11132',
|
||||
'sendq' => '1',
|
||||
'recvq' => '0',
|
||||
'state' => 'ESTABLISHED',
|
||||
'state' => 'TIME_WAIT',
|
||||
'proto' => 'tcp4'
|
||||
}),
|
||||
Net::Connection->new({
|
||||
|
@ -70,9 +70,9 @@ eval{
|
|||
};
|
||||
ok( $worked eq 1, 'sort') or die ('Net::Connection::Sort::state->sorter(@objects) resulted in... '.$@);
|
||||
|
||||
ok( $sorted[0]->local_host eq '2.2.2.2', 'sort order 0') or die ('The first local host value was not 2.2.2.2');
|
||||
ok( $sorted[3]->local_host eq '6.6.6.6', 'sort order 1') or die ('The last local host value was not 6.6.6.6');
|
||||
ok( $sorted[2]->local_host eq '4.4.4.4', 'sort order 2') or die ('The middle local host value was not 4.4.4.4');
|
||||
ok( $sorted[1]->local_host eq '4.4.4.4', 'sort order 2') or die ('The middle local host value was not 4.4.4.4');
|
||||
ok( $sorted[0]->state =~ 'ESTABLISHED', 'sort order 0') or die ('The state for 0 is not ESTABLISHED');
|
||||
ok( $sorted[1]->state =~ 'FIN_WAIT_2', 'sort order 1') or die ('The state for 1 is not FIN_WAIT_2');
|
||||
ok( $sorted[2]->state =~ 'LISTEN', 'sort order 2') or die ('The state for 2 is not LISTEN');
|
||||
ok( $sorted[3]->state =~ 'TIME_WAIT', 'sort order 2') or die ('The state for 3 is not TIME_WAIT');
|
||||
|
||||
done_testing(7);
|
Loading…
Reference in New Issue