Sort/uid.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/ptr_l.pm ↑ Summary Sort/user.pm »
1 package Net::Connection::Sort::uid;
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::uid - Sorts the connections via the UID.
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 Please keep in mind that UID is not a requirement and if not specified is set to 0,
23 meaning it will show up earlier.
24  
25 use Net::Connection::Sort::host_f;
26 use Net::Connection;
27 use Data::Dumper;
28
29 my @objects=(
30 Net::Connection->new({
31 'foreign_host' => '3.3.3.3',
32 'local_host' => '4.4.4.4',
33 'foreign_port' => '22',
34 'local_port' => '11132',
35 'sendq' => '1',
36 'recvq' => '0',
37 'state' => 'ESTABLISHED',
38 'proto' => 'tcp4'
39 'uid' => 33,
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 'uid' => 0,
51 }),
52 Net::Connection->new({
53 'foreign_host' => '5.5.5.5',
54 'local_host' => '6.6.6.6',
55 'foreign_port' => '22',
56 'local_port' => '11132',
57 'sendq' => '1',
58 'recvq' => '0',
59 'state' => 'ESTABLISHED',
60 'proto' => 'tcp4'
61 'uid' => 1000,
62 }),
63 # as no UID is specified, the value of 0 will just be used instead
64 Net::Connection->new({
65 'foreign_host' => '3.3.3.3',
66 'local_host' => '4.4.4.4',
67 'foreign_port' => '22',
68 'local_port' => '11132',
69 'sendq' => '1',
70 'recvq' => '0',
71 'state' => 'ESTABLISHED',
72 'proto' => 'tcp4'
73 }),
74 );
75
76 my $sorter=$sorter=Net::Connection::Sort::uid->new;
77
78 @objects=$sorter->sorter( \@objects );
79
80 print Dumper( \@objects );
81  
82 =head1 METHODS
83  
84 =head2 new
85  
86 This initiates the module.
87  
88 No arguments are taken and this will always succeed.
89  
90 my $sorter=$sorter=Net::Connection::Sort::uid->new;
91  
92 =cut
93  
94 sub new{
95 1 ▶ my %args;
Subroutine new: called CC=2 SCAR=7.6
Pod documented
96 1 ▶ if(defined($_[1])){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) 0 1 1
97 0 %args= %{$_[1]};
98 };
99  
100  
101 1 my $self = {
102 };
103 1 bless $self;
104  
105 1 return $self;
106 }
107  
108 =head2 sort
109  
110 This sorts the array of Net::Connection objects.
111  
112 One object is taken and that is a array of objects.
113  
114 @objects=$sorter->sorter( \@objects );
115
116 print Dumper( \@objects );
117  
118 =cut
119  
120 sub sorter{
121 1 ▶ my $self=$_[0];
Subroutine sorter: called CC=3 SCAR=11.7
Pod undocumented
122 1 my @objects;
123 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
124 defined( $_[1] ) &&
125 ( ref($_[1]) eq 'ARRAY' )
126 ){
127 1 @objects=@{ $_[1] };
128 }else{
129 0 die 'The passed item is either not a array or undefined';
130 }
131  
132 @objects=sort {
133 1 &helper( $a->uid ) <=> &helper( $b->uid )
134 } @objects;
135  
136 1 return @objects;
137 }
138  
139 =head2 helper
140  
141 This is a internal function.
142  
143 If no UID is defined, returns 0.
144  
145 =cut
146  
147 sub helper{
148 8 ▶ if ( !defined($_[0]) ){
Subroutine helper: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_[0]) 2 6 8
149 2 return 0;
150 }
151 6 return $_[0];
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/ptr_l.pm ↑ Summary Sort/user.pm »