Sort/port_fa.pm

filter: Statementstmt 86.2% 25 / 29 Branchbran 50.0% 3 / 6 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 6 / 6 Podpod 66.6% 2 / 3 totaltotal 75.5% 37 / 49 CC 5 SCAR 7.6
CC
5
Cov
76%
sorter
3.2
helper
2.3
new
2.1
CRAP 2.1
« Sort/host_l.pm ↑ Summary Sort/port_la.pm »
1 package Net::Connection::Sort::port_fa;
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  
7 =head1 NAME
8  
9 Net::Connection::Sort::port_fa - Sorts the connections via the foreign port alphabetically.
10  
11 =head1 VERSION
12  
13 Version 0.0.0
14  
15 =cut
16  
17 2 our $VERSION = '0.0.0';
18  
19  
20 =head1 SYNOPSIS
21  
22 This currently implements cmp sorting only. For numeric sorting using port_f.
23  
24 use Net::Connection::Sort::port_f;
25 use Net::Connection;
26 use Data::Dumper;
27
28 my @objects=(
29 Net::Connection->new({
30 'foreign_host' => '3.3.3.3',
31 'local_host' => '4.4.4.4',
32 'foreign_port' => 'FTP',
33 'local_port' => '11132',
34 'sendq' => '1',
35 'recvq' => '0',
36 'state' => 'ESTABLISHED',
37 'proto' => 'tcp4',
38 'ports' => 0,
39 }),
40 Net::Connection->new({
41 'foreign_host' => '1.1.1.1',
42 'local_host' => '2.2.2.2',
43 'foreign_port' => 'SSH',
44 'local_port' => '11132',
45 'sendq' => '1',
46 'recvq' => '0',
47 'state' => 'ESTABLISHED',
48 'proto' => 'tcp4',
49 'ports' => 0,
50 }),
51 Net::Connection->new({
52 'foreign_host' => '5.5.5.5',
53 'local_host' => '6.6.6.6',
54 'foreign_port' => 'HTTP',
55 'local_port' => '11132',
56 'sendq' => '1',
57 'recvq' => '0',
58 'state' => 'ESTABLISHED',
59 'proto' => 'tcp4',
60 'ports' => 0,
61 }),
62 Net::Connection->new({
63 'foreign_host' => '3.3.3.3',
64 'local_host' => '4.4.4.4',
65 'foreign_port' => 'HTTPS',
66 'local_port' => '11132',
67 'sendq' => '1',
68 'recvq' => '0',
69 'state' => 'ESTABLISHED',
70 'proto' => 'tcp4',
71 'ports' => 0,
72 }),
73 );
74
75 my $sorter=$sorter=Net::Connection::Sort::port_fa->new;
76
77 @objects=$sorter->sorter( \@objects );
78
79 print Dumper( \@objects );
80  
81 =head1 METHODS
82  
83 =head2 new
84  
85 This initiates the module.
86  
87 No arguments are taken and this will always succeed.
88  
89 my $sorter=$sorter=Net::Connection::Sort::port_fa->new;
90  
91 =cut
92  
93 sub new{
94 1 ▶ my %args;
Subroutine new: called CC=2 SCAR=7.6
Pod documented
95 1 ▶ if(defined($_[1])){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) 0 1 1
96 0 %args= %{$_[1]};
97 };
98  
99  
100 1 my $self = {
101 };
102 1 bless $self;
103  
104 1 return $self;
105 }
106  
107 =head2 sort
108  
109 This sorts the array of Net::Connection objects.
110  
111 One object is taken and that is a array of objects.
112  
113 @objects=$sorter->sorter( \@objects );
114
115 print Dumper( \@objects );
116  
117 =cut
118  
119 sub sorter{
120 1 ▶ my $self=$_[0];
Subroutine sorter: called CC=3 SCAR=11.7
Pod undocumented
121 1 my @objects;
122 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
123 defined( $_[1] ) &&
124 ( ref($_[1]) eq 'ARRAY' )
125 ){
126 1 @objects=@{ $_[1] };
127 }else{
128 0 die 'The passed item is either not a array or undefined';
129 }
130  
131 @objects=sort {
132 1 &helper( $a ) cmp &helper( $b )
133 } @objects;
134  
135 1 return @objects;
136 }
137  
138 =head2 helper
139  
140 =cut
141  
142 sub helper{
143 8 ▶ if ( !defined( $_[0]->foreign_port_name ) ){
Subroutine helper: called CC=2 SCAR=8.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_[0]->foreign_port_name) 0 8 8
144 0 return $_[0]->foreign_port;
145 }
146 8 return $_[0]->foreign_port_name;
147 }
148  
149 =head1 AUTHOR
150  
151 Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
152  
153 =head1 BUGS
154  
155 Please report any bugs or feature requests to C<bug-net-connection-sort at rt.cpan.org>, or through
156 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Connection-Sort>. I will be notified, and then you'll
157 automatically be notified of progress on your bug as I make changes.
158  
159  
160  
161  
162 =head1 SUPPORT
163  
164 You can find documentation for this module with the perldoc command.
165  
166 perldoc Net::Connection::Sort
167  
168  
169 You can also look for information at:
170  
171 =over 4
172  
173 =item * RT: CPAN's request tracker (report bugs here)
174  
175 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Connection-Sort>
176  
177 =item * AnnoCPAN: Annotated CPAN documentation
178  
179 L<http://annocpan.org/dist/Net-Connection-Sort>
180  
181 =item * CPAN Ratings
182  
183 L<https://cpanratings.perl.org/d/Net-Connection-Sort>
184  
185 =item * Search CPAN
186  
187 L<https://metacpan.org/release/Net-Connection-Sort>
188  
189 =item * Git Repo
190  
191 L<https://gitea.eesdp.org/vvelox/Net-Connection-Sort>
192  
193 =back
194  
195  
196 =head1 ACKNOWLEDGEMENTS
197  
198  
199 =head1 LICENSE AND COPYRIGHT
200  
201 This software is Copyright (c) 2019 by Zane C. Bowers-Hadley.
202  
203 This is free software, licensed under:
204  
205 The Artistic License 2.0 (GPL Compatible)
206  
207  
208 =cut
209  
210 2 1; # End of Net::Connection::Sort
« Sort/host_l.pm ↑ Summary Sort/port_la.pm »