Sort/ptr_l.pm

filter: Statementstmt 96.0% 24 / 25 Branchbran 75.0% 3 / 4 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 6 / 6 Podpod 100% 3 / 3 totaltotal 86.0% 37 / 43 CC 4 SCAR 6.7
CC
4
Cov
88%
sorter
3.2
helper
2.0
BEGIN
1.0
CRAP 2.0
« Sort/ptr_f.pm ↑ Summary Sort/uid.pm »
1 package Net::Connection::Sort::ptr_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::ptr_l - Sorts via the foriegn PTR.
10  
11 =head1 VERSION
12  
13 Version 0.0.2
14  
15 =cut
16  
17 2 our $VERSION = '0.0.2';
18  
19  
20 =head1 SYNOPSIS
21  
22 If a local PTR could not be found or is not set, then the foreign host is used.
23  
24 use Net::Connection::Sort::ptr_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' => '22',
33 'local_port' => '11132',
34 'sendq' => '1',
35 'recvq' => '0',
36 'state' => 'ESTABLISHED',
37 'proto' => 'tcp4',
38 'ptrs' => 0,
39 'local_ptr' => 'c.foo',
40 }),
41 Net::Connection->new({
42 'foreign_host' => '1.1.1.1',
43 'local_host' => '2.2.2.2',
44 'foreign_port' => '22',
45 'local_port' => '11132',
46 'sendq' => '1',
47 'recvq' => '0',
48 'state' => 'ESTABLISHED',
49 'proto' => 'tcp4',
50 'ptrs' => 0,
51 'local_ptr' => 'a.foo',
52 }),
53 Net::Connection->new({
54 'foreign_host' => '5.5.5.5',
55 'local_host' => '6.6.6.6',
56 'foreign_port' => '22',
57 'local_port' => '11132',
58 'sendq' => '1',
59 'recvq' => '0',
60 'state' => 'ESTABLISHED',
61 'proto' => 'tcp4',
62 'ptrs' => 0,
63 'local_ptr' => 'b.foo',
64 }),
65 Net::Connection->new({
66 'foreign_host' => '3.3.3.3',
67 'local_host' => '4.4.4.4',
68 'foreign_port' => '22',
69 'local_port' => '11132',
70 'sendq' => '1',
71 'recvq' => '0',
72 'state' => 'ESTABLISHED',
73 'proto' => 'tcp4'
74 }),
75 );
76
77 my $sorter=Net::Connection::Sort::ptr_l->new;
78
79 @objects=$sorter->sorter( \@objects );
80
81 print Dumper( \@objects );
82  
83 =head1 METHODS
84  
85 =head2 new
86  
87 This initiates the module.
88  
89 No arguments are taken and this will always succeed.
90  
91 my $sorter=Net::Connection::Sort::ptr_l->new;
92  
93 =cut
94  
95 1 ▶sub new{
Subroutine new: called CC=1 SCAR=0.0
Pod documented
96 1 my $self = {
97 };
98 1 bless $self;
99  
100 1 return $self;
101 }
102  
103 =head2 sorter
104  
105 This sorts the array of Net::Connection objects.
106  
107 One object is taken and that is a array of objects.
108  
109 @objects=$sorter->sorter( \@objects );
110
111 print Dumper( \@objects );
112  
113 =cut
114  
115 2 ▶sub sorter{
Subroutine sorter: called CC=3 SCAR=11.7
Pod documented
116 2 my $self=$_[0];
117 2 my @objects;
118 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
119 defined( $_[1] ) &&
120 ( ref($_[1]) eq 'ARRAY' )
121 ){
122 2 @objects=@{ $_[1] };
123 }else{
124 0 die 'The passed item is either not a array or undefined';
125 }
126  
127 @objects=sort {
128 2 helper( $a ) cmp helper( $b )
129 } @objects;
130  
131 2 return @objects;
132 }
133  
134 =head2 helper
135  
136 This is a internal function.
137  
138 If the local PTR is not defined, the local host is returned.
139  
140 =cut
141  
142 16 ▶sub helper{
Subroutine helper: called CC=2 SCAR=6.9
Pod documented
143 16 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_[0]->local_ptr) 6 10 16
144 ( !defined($_[0]->local_ptr ) )
145 ){
146 6 return $_[0]->local_host;
147 }
148 10 return $_[0]->local_ptr;
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/ptr_f.pm ↑ Summary Sort/uid.pm »