host_fl works now

This commit is contained in:
Zane C. B-H 2019-07-23 05:26:29 -05:00
parent 24e83bceb3
commit d7ac702e62
2 changed files with 15 additions and 14 deletions

View File

@ -1,4 +1,4 @@
package Net::Connection::Sort::host_f;
package Net::Connection::Sort::host_fl;
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::host_fl - Sorts the connections via the foreign host and then local host.
=head1 VERSION
@ -20,7 +20,7 @@ our $VERSION = '0.0.0';
=head1 SYNOPSIS
use Net::Connection::Sort::host_f;
use Net::Connection::Sort::host_fl;
use Net::Connection;
use Data::Dumper;
@ -67,7 +67,7 @@ our $VERSION = '0.0.0';
}),
);
my $sorter=$sorter=Net::Connection::Sort::host_f->new;
my $sorter=$sorter=Net::Connection::Sort::host_fl->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::host_fl->new;
=cut
@ -124,7 +124,8 @@ sub sorter{
}
@objects=sort {
&helper( $a->foreign_host ) <=> &helper( $b->foreign_host )
&helper( $a->{foreign_host} ) <=> &helper( $b->{foreign_host} ) or
&helper( $a->{local_host} ) <=> &helper( $b->{local_host} )
} @objects;
return @objects;

View File

@ -38,7 +38,7 @@ my @objects=(
}),
Net::Connection->new({
'foreign_host' => '3.3.3.3',
'local_host' => '4.4.4.4',
'local_host' => '4.4.4.5',
'foreign_port' => '22',
'local_port' => '11132',
'sendq' => '1',
@ -49,18 +49,18 @@ my @objects=(
);
BEGIN {
use_ok( 'Net::Connection::Sort::host_f' ) || print "Bail out!\n";
use_ok( 'Net::Connection::Sort::host_fl' ) || print "Bail out!\n";
}
diag( "Testing Net::Connection::Sort::host_f $Net::Connection::Sort::host_f::VERSION, Perl $], $^X" );
diag( "Testing Net::Connection::Sort::host_fl $Net::Connection::Sort::host_fl::VERSION, Perl $], $^X" );
my $sorter;
my $worked=0;
eval{
$sorter=Net::Connection::Sort::host_f->new;
$sorter=Net::Connection::Sort::host_fl->new;
$worked=1;
};
ok( $worked eq 1, 'sorter init') or die ('Net::Connection::Sort::host_f->new resulted in... '.$@);
ok( $worked eq 1, 'sorter init') or die ('Net::Connection::Sort::host_fl->new resulted in... '.$@);
my @sorted;
$worked=0;
@ -68,11 +68,11 @@ eval{
@sorted=$sorter->sorter( \@objects );
$worked=1;
};
ok( $worked eq 1, 'sort') or die ('Net::Connection::Sort::host_f->sorter(@objects) resulted in... '.$@);
ok( $worked eq 1, 'sort') or die ('Net::Connection::Sort::host_fl->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');
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[2]->local_host eq '4.4.4.5', 'sort order 3') or die ('The middle local host value was not 4.4.4.5');
done_testing(7);