Sort/ptr_f.pm

filter: Statementstmt 89.6% 26 / 29 Branchbran 66.6% 4 / 6 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 6 / 6 Podpod 66.6% 2 / 3 totaltotal 79.5% 39 / 49 CC 5 SCAR 7.4
CC
5
Cov
82%
sorter
3.2
new
2.1
helper
2.0
CRAP 2.1
« Sort/pid.pm ↑ Summary Sort/ptr_l.pm »
1 package Net::Connection::Sort::ptr_f;
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_f - Sorts via the foriegn PTR.
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 If a foriegn PTR could not be found or is not set, then the foreign host is used.
23  
24 use Net::Connection::Sort::ptr_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' => '22',
33 'local_port' => '11132',
34 'sendq' => '1',
35 'recvq' => '0',
36 'state' => 'ESTABLISHED',
37 'proto' => 'tcp4',
38 'ptrs' => 0,
39 'foreign_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 'foreign_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 'foreign_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=$sorter=Net::Connection::Sort::ptr_f->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=$sorter=Net::Connection::Sort::ptr_f->new;
92  
93 =cut
94  
95 sub new{
96 1 ▶ my %args;
Subroutine new: called CC=2 SCAR=7.6
Pod documented
97 1 ▶ if(defined($_[1])){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) 0 1 1
98 0 %args= %{$_[1]};
99 };
100  
101  
102 1 my $self = {
103 };
104 1 bless $self;
105  
106 1 return $self;
107 }
108  
109 =head2 sort
110  
111 This sorts the array of Net::Connection objects.
112  
113 One object is taken and that is a array of objects.
114  
115 @objects=$sorter->sorter( \@objects );
116
117 print Dumper( \@objects );
118  
119 =cut
120  
121 sub sorter{
122 1 ▶ my $self=$_[0];
Subroutine sorter: called CC=3 SCAR=11.7
Pod undocumented
123 1 my @objects;
124 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
125 defined( $_[1] ) &&
126 ( ref($_[1]) eq 'ARRAY' )
127 ){
128 1 @objects=@{ $_[1] };
129 }else{
130 0 die 'The passed item is either not a array or undefined';
131 }
132  
133 @objects=sort {
134 1 &helper( $a ) cmp &helper( $b )
135 } @objects;
136  
137 1 return @objects;
138 }
139  
140 =head2 helper
141  
142 This is a internal function.
143  
144 If the foreign PTR is not defined, the foreign host is returned.
145  
146 =cut
147  
148 sub helper{
149 10 ▶ if (
Subroutine helper: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_[0]->foreign_ptr) 2 8 10
150 ( !defined($_[0]->foreign_ptr ) )
151 ){
152 2 return $_[0]->foreign_host;
153 }
154 8 return $_[0]->foreign_ptr;
155 }
156  
157 =head1 AUTHOR
158  
159 Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
160  
161 =head1 BUGS
162  
163 Please report any bugs or feature requests to C<bug-net-connection-sort at rt.cpan.org>, or through
164 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Connection-Sort>. I will be notified, and then you'll
165 automatically be notified of progress on your bug as I make changes.
166  
167  
168  
169  
170 =head1 SUPPORT
171  
172 You can find documentation for this module with the perldoc command.
173  
174 perldoc Net::Connection::Sort
175  
176  
177 You can also look for information at:
178  
179 =over 4
180  
181 =item * RT: CPAN's request tracker (report bugs here)
182  
183 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Connection-Sort>
184  
185 =item * AnnoCPAN: Annotated CPAN documentation
186  
187 L<http://annocpan.org/dist/Net-Connection-Sort>
188  
189 =item * CPAN Ratings
190  
191 L<https://cpanratings.perl.org/d/Net-Connection-Sort>
192  
193 =item * Search CPAN
194  
195 L<https://metacpan.org/release/Net-Connection-Sort>
196  
197 =item * Git Repo
198  
199 L<https://gitea.eesdp.org/vvelox/Net-Connection-Sort>
200  
201 =back
202  
203  
204 =head1 ACKNOWLEDGEMENTS
205  
206  
207 =head1 LICENSE AND COPYRIGHT
208  
209 This software is Copyright (c) 2019 by Zane C. Bowers-Hadley.
210  
211 This is free software, licensed under:
212  
213 The Artistic License 2.0 (GPL Compatible)
214  
215  
216 =cut
217  
218 2 1; # End of Net::Connection::Sort
« Sort/pid.pm ↑ Summary Sort/ptr_l.pm »