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