Sort/host_l.pm

filter: Statementstmt 86.1% 31 / 36 Branchbran 50.0% 4 / 8 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 7 / 7 Podpod 66.6% 2 / 3 totaltotal 69.1% 47 / 68 CC 8 SCAR 13.9
CC
8
Cov
72%
helper
7.6
sorter
3.2
new
2.1
CRAP 4.0
« Sort/host_f.pm ↑ Summary Sort/port_fa.pm »
1 package Net::Connection::Sort::host_l;
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_l - Sorts the connections via the local 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_l;
24 use Net::Connection;
25 use Data::Dumper;
26
27 my @objects=(
28 Net::Connection->new({
29 'foreign_host' => '3.3.3.3',
30 'local_host' => '4.4.4.4',
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_l->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_l->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
BranchTrueFalseTotal
if (defined $_[1]) 0 1 1
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=3 SCAR=11.7
Pod undocumented
116 1 my @objects;
117 1 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1] and ref $_[1] eq 'ARRAY') { } 1 0 1
Condition33%1/3
defined $_[1] and ref $_[1] eq "ARRAY"
!ll&&!rl&&r
001
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"
ABresult
0X0
100
111
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 )
128 } @objects;
129  
130 1 return @objects;
131 }
132  
133 =head2 helper
134  
135 This is a internal function.
136  
137 =cut
138  
139 sub helper{
140 8 ▶ if (
Subroutine helper: called CC=5 SCAR=20.3
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $_[0] or $_[0] eq "*" or $_[0] =~ /[g-zG-Z]/) 0 8 8
Condition33%2/6
not defined $_[0] or $_[0] eq "*" or $_[0] =~ /[g-zG-Z]/
l!l&&r!l&&!r
008
not defined $_[0] or $_[0] eq "*"
l!l&&r!l&&!r
008
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]/
ABCresult
1XX1
01X1
0011
0000
141 ( !defined($_[0]) ) ||
142 ( $_[0] eq '*' ) ||
143 ( $_[0] =~ /[g-zG-Z]/ )
144 ){
145 0 return 0;
146 }
147 8 my $host=eval { Net::IP->new( $_[0] )->intip} ;
148 8 ▶ if (!defined( $host )){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $host) 0 8 8
149 0 return 0;
150 }
151 8 return $host;
152 }
153  
154 =head1 AUTHOR
155  
156 Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
157  
158 =head1 BUGS
159  
160 Please report any bugs or feature requests to C<bug-net-connection-sort at rt.cpan.org>, or through
161 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Connection-Sort>. I will be notified, and then you'll
162 automatically be notified of progress on your bug as I make changes.
163  
164  
165  
166  
167 =head1 SUPPORT
168  
169 You can find documentation for this module with the perldoc command.
170  
171 perldoc Net::Connection::Sort
172  
173  
174 You can also look for information at:
175  
176 =over 4
177  
178 =item * RT: CPAN's request tracker (report bugs here)
179  
180 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Connection-Sort>
181  
182 =item * AnnoCPAN: Annotated CPAN documentation
183  
184 L<http://annocpan.org/dist/Net-Connection-Sort>
185  
186 =item * CPAN Ratings
187  
188 L<https://cpanratings.perl.org/d/Net-Connection-Sort>
189  
190 =item * Search CPAN
191  
192 L<https://metacpan.org/release/Net-Connection-Sort>
193  
194 =item * Git Repo
195  
196 L<https://gitea.eesdp.org/vvelox/Net-Connection-Sort>
197  
198 =back
199  
200  
201 =head1 ACKNOWLEDGEMENTS
202  
203  
204 =head1 LICENSE AND COPYRIGHT
205  
206 This software is Copyright (c) 2019 by Zane C. Bowers-Hadley.
207  
208 This is free software, licensed under:
209  
210 The Artistic License 2.0 (GPL Compatible)
211  
212  
213 =cut
214  
215 2 1; # End of Net::Connection::Sort
« Sort/host_f.pm ↑ Summary Sort/port_fa.pm »