host_lf works

This commit is contained in:
Zane C. B-H 2019-07-23 05:36:06 -05:00
parent 7071a3c61c
commit df9a89d9e4
3 changed files with 13 additions and 10 deletions

View File

@ -3,6 +3,7 @@ lib/Net/Connection/Sort.pm
lib/Net/Connection/Sort/host_f.pm
lib/Net/Connection/Sort/host_fl.pm
lib/Net/Connection/Sort/host_l.pm
lib/Net/Connection/Sort/host_lf.pm
Makefile.PL
MANIFEST This list of files
README
@ -10,9 +11,11 @@ t/00-load.t
t/01-load.t
t/02-load.t
t/03-load.t
t/04-load.t
t/manifest.t
t/pod-coverage.t
t/pod.t
t/host_f.t
t/host_fl.t
t/host_l.t
t/host_lf.t

View File

@ -1,4 +1,4 @@
package Net::Connection::Sort::host_fl;
package Net::Connection::Sort::host_lf;
use 5.006;
use strict;
@ -7,7 +7,7 @@ use Net::IP;
=head1 NAME
Net::Connection::Sort::host_fl - Sorts the connections via the foreign host and then local host.
Net::Connection::Sort::host_lf - Sorts the connections via the local host and then foreign host.
=head1 VERSION
@ -26,7 +26,7 @@ our $VERSION = '0.0.0';
my @objects=(
Net::Connection->new({
'foreign_host' => '3.3.3.3',
'foreign_host' => '3.3.3.4',
'local_host' => '4.4.4.5',
'foreign_port' => '22',
'local_port' => '11132',
@ -67,7 +67,7 @@ our $VERSION = '0.0.0';
}),
);
my $sorter=$sorter=Net::Connection::Sort::host_fl->new;
my $sorter=$sorter=Net::Connection::Sort::host_lf->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_fl->new;
my $sorter=$sorter=Net::Connection::Sort::host_lf->new;
=cut
@ -124,8 +124,8 @@ sub sorter{
}
@objects=sort {
&helper( $a->{foreign_host} ) <=> &helper( $b->{foreign_host} ) or
&helper( $a->{local_host} ) <=> &helper( $b->{local_host} )
&helper( $a->{local_host} ) <=> &helper( $b->{local_host} ) or
&helper( $a->{foreign_host} ) <=> &helper( $b->{foreign_host} )
} @objects;
return @objects;

View File

@ -7,7 +7,7 @@ use Net::Connection;
my @objects=(
Net::Connection->new({
'foreign_host' => '3.3.3.3',
'foreign_host' => '3.3.3.4',
'local_host' => '4.4.4.4',
'foreign_port' => '22',
'local_port' => '11132',
@ -72,7 +72,7 @@ ok( $worked eq 1, 'sort') or die ('Net::Connection::Sort::host_lf->sorter(@objec
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[1]->foreign_host eq '3.3.3.3', 'sort order 2') or die ('The second foreign host value was not 3.3.3.3');
ok( $sorted[2]->foreign_host eq '3.3.3.4', 'sort order 3') or die ('The third foreign host value was not 3.3.3.4');
done_testing(7);