Sort/port_l.pm

filter: Statementstmt 96.0% 24 / 25 Branchbran 75.0% 3 / 4 Conditioncond 50.0% 3 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 6 / 6 Podpod 100% 3 / 3 totaltotal 83.3% 40 / 48 CC 5 SCAR 8.2
CC
5
Cov
86%
sorter
3.2
helper
3.0
BEGIN
1.0
CRAP 2.3
« Sort/port_f.pm ↑ Summary Sort/unsorted.pm »
1 package Net::Connection::Sort::port_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  
7 =head1 NAME
8  
9 Net::Connection::Sort::port_l - Sorts the connections via the local port numerically.
10  
11 =head1 VERSION
12  
13 Version 0.1.2
14  
15 =cut
16  
17 2 our $VERSION = '0.1.2';
18  
19  
20 =head1 SYNOPSIS
21  
22 This currently implements numeric sorting only. For non-numeric sorting using port_la.
23  
24 use Net::Connection::Sort::port_l;
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' => '23',
33 'local_port' => '1133',
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' => '22',
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' => '80',
55 'local_port' => '11131',
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' => '21',
66 'local_port' => '11133',
67 'sendq' => '1',
68 'recvq' => '0',
69 'state' => 'ESTABLISHED',
70 'proto' => 'tcp4',
71 'ports' => 0,
72 }),
73 );
74
75 my $sorter=Net::Connection::Sort::port_l->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=Net::Connection::Sort::port_l->new;
90  
91 =cut
92  
93 1 ▶sub new{
Subroutine new: called CC=1 SCAR=0.0
Pod documented
94 1 my $self = {
95 };
96 1 bless $self;
97  
98 1 return $self;
99 }
100  
101 =head2 sorter
102  
103 This sorts the array of Net::Connection objects.
104  
105 One object is taken and that is a array of objects.
106  
107 @objects=$sorter->sorter( \@objects );
108
109 print Dumper( \@objects );
110  
111 =cut
112  
113 2 ▶sub sorter{
Subroutine sorter: called CC=3 SCAR=11.7
Pod documented
114 2 my $self=$_[0];
115 2 my @objects;
116 2 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1] and ref $_[1] eq 'ARRAY') { } 2 0 2
Condition33%1/3
defined $_[1] and ref $_[1] eq "ARRAY"
!ll&&!rl&&r
002
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
117 defined( $_[1] ) &&
118 ( ref($_[1]) eq 'ARRAY' )
119 ){
120 2 @objects=@{ $_[1] };
121 }else{
122 0 die 'The passed item is either not a array or undefined';
123 }
124  
125 @objects=sort {
126 2 helper( $a->local_port ) <=> helper( $b->local_port )
127 } @objects;
128  
129 2 return @objects;
130 }
131  
132 =head2 helper
133  
134 This is a internal function.
135  
136 Returns the value to sort the passed port on. Anything not numeric, such as
137 the '*' used for a wildcard port, becomes 0.
138  
139 =cut
140  
141 16 ▶sub helper{
Subroutine helper: called CC=3 SCAR=11.0
Pod documented
142 16 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_[0] and $_[0] =~ /^[0-9]+$/) 2 14 16
Condition66%2/3
defined $_[0] and $_[0] =~ /^[0-9]+$/
!ll&&!rl&&r
0214
MC/DC50%1/2
defined $_[0] and $_[0] =~ /^[0-9]+$/
defined $_[0] $_[0] =~ /^[0-9]+$/
Truth table66%2/3
A and B
A= defined $_[0]B= $_[0] =~ /^[0-9]+$/
ABresult
0X0
100
111
143 ( !defined($_[0]) ) ||
144 ( $_[0] !~ /^[0-9]+$/ )
145 ){
146 2 return 0;
147 }
148 14 return $_[0];
149 }
150  
151 =head1 AUTHOR
152  
153 Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
154  
155 =head1 BUGS
156  
157 Please report any bugs or feature requests to C<bug-net-connection-sort at rt.cpan.org>, or through
158 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Connection-Sort>. I will be notified, and then you'll
159 automatically be notified of progress on your bug as I make changes.
160  
161  
162  
163  
164 =head1 SUPPORT
165  
166 You can find documentation for this module with the perldoc command.
167  
168 perldoc Net::Connection::Sort
169  
170  
171 You can also look for information at:
172  
173 =over 4
174  
175 =item * RT: CPAN's request tracker (report bugs here)
176  
177 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Connection-Sort>
178  
179 =item * Search CPAN
180  
181 L<https://metacpan.org/release/Net-Connection-Sort>
182  
183 =item * Git Repo
184  
185 L<https://gitea.eesdp.org/vvelox/Net-Connection-Sort>
186  
187 =back
188  
189  
190 =head1 ACKNOWLEDGEMENTS
191  
192  
193 =head1 LICENSE AND COPYRIGHT
194  
195 This software is Copyright (c) 2019 by Zane C. Bowers-Hadley.
196  
197 This is free software, licensed under:
198  
199 The Artistic License 2.0 (GPL Compatible)
200  
201  
202 =cut
203  
204 2 1; # End of Net::Connection::Sort
« Sort/port_f.pm ↑ Summary Sort/unsorted.pm »