basics all documented... host_f works... added new depend, Net::IP
This commit is contained in:
parent
a0ef786189
commit
561260c449
|
@ -18,6 +18,7 @@ my %WriteMakefileArgs = (
|
|||
},
|
||||
PREREQ_PM => {
|
||||
'Net::Connection'=>'0.0.0',
|
||||
'Net::IP'=>'1.26',
|
||||
},
|
||||
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
|
||||
clean => { FILES => 'Net-Connection-Sort-*' },
|
||||
|
|
|
@ -22,6 +22,50 @@ our $VERSION = '0.0.0';
|
|||
|
||||
use Net::Connection::Sort;
|
||||
use Net::Connection;
|
||||
use Data::Dumper;
|
||||
|
||||
my @objects=(
|
||||
Net::Connection->new({
|
||||
'foreign_host' => '3.3.3.3',
|
||||
'local_host' => '4.4.4.4',
|
||||
'foreign_port' => '22',
|
||||
'local_port' => '11132',
|
||||
'sendq' => '1',
|
||||
'recvq' => '0',
|
||||
'state' => 'ESTABLISHED',
|
||||
'proto' => 'tcp4'
|
||||
}),
|
||||
Net::Connection->new({
|
||||
'foreign_host' => '1.1.1.1',
|
||||
'local_host' => '2.2.2.2',
|
||||
'foreign_port' => '22',
|
||||
'local_port' => '11132',
|
||||
'sendq' => '1',
|
||||
'recvq' => '0',
|
||||
'state' => 'ESTABLISHED',
|
||||
'proto' => 'tcp4'
|
||||
}),
|
||||
Net::Connection->new({
|
||||
'foreign_host' => '5.5.5.5',
|
||||
'local_host' => '6.6.6.6',
|
||||
'foreign_port' => '22',
|
||||
'local_port' => '11132',
|
||||
'sendq' => '1',
|
||||
'recvq' => '0',
|
||||
'state' => 'ESTABLISHED',
|
||||
'proto' => 'tcp4'
|
||||
}),
|
||||
Net::Connection->new({
|
||||
'foreign_host' => '3.3.3.3',
|
||||
'local_host' => '4.4.4.4',
|
||||
'foreign_port' => '22',
|
||||
'local_port' => '11132',
|
||||
'sendq' => '1',
|
||||
'recvq' => '0',
|
||||
'state' => 'ESTABLISHED',
|
||||
'proto' => 'tcp4'
|
||||
}),
|
||||
);
|
||||
|
||||
my $sort_args={
|
||||
type=>'host_f',
|
||||
|
@ -30,12 +74,16 @@ our $VERSION = '0.0.0';
|
|||
|
||||
my $mcs;
|
||||
eval{
|
||||
$ncs=Net::Connection::Sort->new( $sort_args );
|
||||
$mcs=Net::Connection::Sort->new( $sort_args );
|
||||
};
|
||||
|
||||
if ( ! defined( $mcs ) ){
|
||||
print "Failed to init the sorter... ".$@;
|
||||
}
|
||||
|
||||
my @sorted=$mcs->sorter( \@objects );
|
||||
|
||||
print Dumper( \@sorted );
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
|
@ -109,12 +157,16 @@ sub new{
|
|||
return $self;
|
||||
}
|
||||
|
||||
=head2 sort
|
||||
=head2 sorter
|
||||
|
||||
This sorts the array of Net::Connection objects.
|
||||
|
||||
One object is taken and that is a array of objects.
|
||||
|
||||
my @sorted=$mcs->sorter( \@objects );
|
||||
|
||||
print Dumper( \@sorted );
|
||||
|
||||
=cut
|
||||
|
||||
sub sorter{
|
||||
|
|
|
@ -3,10 +3,11 @@ package Net::Connection::Sort::host_f;
|
|||
use 5.006;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Net::IP;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Net::Connection::Sort - Sorts array of Net::Connection objects.
|
||||
Net::Connection::Sort::host_f - Sorts the connections via the foreign host.
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
|
@ -21,8 +22,56 @@ our $VERSION = '0.0.0';
|
|||
|
||||
use Net::Connection::Sort::host_f;
|
||||
use Net::Connection;
|
||||
use Data::Dumper;
|
||||
|
||||
my $ncs=Net::Connection::Sort::host_f->new;
|
||||
my @objects=(
|
||||
Net::Connection->new({
|
||||
'foreign_host' => '3.3.3.3',
|
||||
'local_host' => '4.4.4.4',
|
||||
'foreign_port' => '22',
|
||||
'local_port' => '11132',
|
||||
'sendq' => '1',
|
||||
'recvq' => '0',
|
||||
'state' => 'ESTABLISHED',
|
||||
'proto' => 'tcp4'
|
||||
}),
|
||||
Net::Connection->new({
|
||||
'foreign_host' => '1.1.1.1',
|
||||
'local_host' => '2.2.2.2',
|
||||
'foreign_port' => '22',
|
||||
'local_port' => '11132',
|
||||
'sendq' => '1',
|
||||
'recvq' => '0',
|
||||
'state' => 'ESTABLISHED',
|
||||
'proto' => 'tcp4'
|
||||
}),
|
||||
Net::Connection->new({
|
||||
'foreign_host' => '5.5.5.5',
|
||||
'local_host' => '6.6.6.6',
|
||||
'foreign_port' => '22',
|
||||
'local_port' => '11132',
|
||||
'sendq' => '1',
|
||||
'recvq' => '0',
|
||||
'state' => 'ESTABLISHED',
|
||||
'proto' => 'tcp4'
|
||||
}),
|
||||
Net::Connection->new({
|
||||
'foreign_host' => '3.3.3.3',
|
||||
'local_host' => '4.4.4.4',
|
||||
'foreign_port' => '22',
|
||||
'local_port' => '11132',
|
||||
'sendq' => '1',
|
||||
'recvq' => '0',
|
||||
'state' => 'ESTABLISHED',
|
||||
'proto' => 'tcp4'
|
||||
}),
|
||||
);
|
||||
|
||||
my $sorter=$sorter=Net::Connection::Sort::host_f->new;
|
||||
|
||||
@objects=$sorter->sorter( \@objects );
|
||||
|
||||
print Dumper( \@objects );
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
|
@ -54,6 +103,10 @@ This sorts the array of Net::Connection objects.
|
|||
|
||||
One object is taken and that is a array of objects.
|
||||
|
||||
@objects=$sorter->sorter( \@objects );
|
||||
|
||||
print Dumper( \@objects );
|
||||
|
||||
=cut
|
||||
|
||||
sub sorter{
|
||||
|
@ -77,6 +130,8 @@ sub sorter{
|
|||
|
||||
=head2 helper
|
||||
|
||||
This is a internal function.
|
||||
|
||||
=cut
|
||||
|
||||
sub helper{
|
||||
|
|
|
@ -3,11 +3,76 @@ use 5.006;
|
|||
use strict;
|
||||
use warnings;
|
||||
use Test::More;
|
||||
use Net::Connection;
|
||||
|
||||
plan tests => 1;
|
||||
my @objects=(
|
||||
Net::Connection->new({
|
||||
'foreign_host' => '3.3.3.3',
|
||||
'local_host' => '4.4.4.4',
|
||||
'foreign_port' => '22',
|
||||
'local_port' => '11132',
|
||||
'sendq' => '1',
|
||||
'recvq' => '0',
|
||||
'state' => 'ESTABLISHED',
|
||||
'proto' => 'tcp4'
|
||||
}),
|
||||
Net::Connection->new({
|
||||
'foreign_host' => '1.1.1.1',
|
||||
'local_host' => '2.2.2.2',
|
||||
'foreign_port' => '22',
|
||||
'local_port' => '11132',
|
||||
'sendq' => '1',
|
||||
'recvq' => '0',
|
||||
'state' => 'ESTABLISHED',
|
||||
'proto' => 'tcp4'
|
||||
}),
|
||||
Net::Connection->new({
|
||||
'foreign_host' => '5.5.5.5',
|
||||
'local_host' => '6.6.6.6',
|
||||
'foreign_port' => '22',
|
||||
'local_port' => '11132',
|
||||
'sendq' => '1',
|
||||
'recvq' => '0',
|
||||
'state' => 'ESTABLISHED',
|
||||
'proto' => 'tcp4'
|
||||
}),
|
||||
Net::Connection->new({
|
||||
'foreign_host' => '3.3.3.3',
|
||||
'local_host' => '4.4.4.4',
|
||||
'foreign_port' => '22',
|
||||
'local_port' => '11132',
|
||||
'sendq' => '1',
|
||||
'recvq' => '0',
|
||||
'state' => 'ESTABLISHED',
|
||||
'proto' => 'tcp4'
|
||||
}),
|
||||
);
|
||||
|
||||
BEGIN {
|
||||
use_ok( 'Net::Connection::Sort::host_f' ) || print "Bail out!\n";
|
||||
}
|
||||
|
||||
diag( "Testing Net::Connection::Sort::host_f $Net::Connection::Sort::host_f::VERSION, Perl $], $^X" );
|
||||
|
||||
my $sorter;
|
||||
my $worked=0;
|
||||
eval{
|
||||
$sorter=Net::Connection::Sort::host_f->new;
|
||||
$worked=1;
|
||||
};
|
||||
ok( $worked eq 1, 'sorter init') or die ('Net::Connection::Sort::host_f->new resulted in... '.$@);
|
||||
|
||||
my @sorted;
|
||||
$worked=0;
|
||||
eval{
|
||||
@sorted=$sorter->sorter( \@objects );
|
||||
$worked=1;
|
||||
};
|
||||
ok( $worked eq 1, 'sort') or die ('Net::Connection::Sort::host_f->sorter(@objects) resulted in... '.$@);
|
||||
|
||||
ok( $sorted[0]->foreign_host eq '1.1.1.1', 'sort order 0') or die ('The first foreign host value was not 1.1.1.1');
|
||||
ok( $sorted[3]->foreign_host eq '5.5.5.5', 'sort order 1') or die ('The last foreign host value was not 5.5.5.5');
|
||||
ok( $sorted[2]->foreign_host eq '3.3.3.3', 'sort order 2') or die ('The middle foreign host value was not 3.3.3.3');
|
||||
ok( $sorted[1]->foreign_host eq '3.3.3.3', 'sort order 2') or die ('The middle foreign host value was not 3.3.3.3');
|
||||
|
||||
done_testing(7);
|
||||
|
|
Loading…
Reference in New Issue