Sort/state.pm

filter: Statementstmt 95.4% 21 / 22 Branchbran 50.0% 1 / 2 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 5 / 5 Podpod 100% 2 / 2 totaltotal 83.3% 30 / 36 CC 3 SCAR 6.7
CC
3
Cov
85%
sorter
3.2
BEGIN
1.0
BEGIN
1.0
CRAP 1.9
« Sort/proto.pm ↑ Summary Sort/pid.pm »
1 package Net::Connection::Sort::state;
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::state - Sorts the connections via the connection state.
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 use Net::Connection::Sort::state;
23 use Net::Connection;
24 use Data::Dumper;
25
26 my @objects=(
27 Net::Connection->new({
28 'foreign_host' => '3.3.3.3',
29 'local_host' => '4.4.4.4',
30 'foreign_port' => '22',
31 'local_port' => '11132',
32 'sendq' => '1',
33 'recvq' => '0',
34 'state' => 'LISTEN',
35 'proto' => 'tcp4'
36 }),
37 Net::Connection->new({
38 'foreign_host' => '1.1.1.1',
39 'local_host' => '2.2.2.2',
40 'foreign_port' => '22',
41 'local_port' => '11132',
42 'sendq' => '1',
43 'recvq' => '0',
44 'state' => 'FIN_WAIT_2',
45 'proto' => 'tcp4'
46 }),
47 Net::Connection->new({
48 'foreign_host' => '5.5.5.5',
49 'local_host' => '6.6.6.6',
50 'foreign_port' => '22',
51 'local_port' => '11132',
52 'sendq' => '1',
53 'recvq' => '0',
54 'state' => 'TIME_WAIT',
55 'proto' => 'tcp4'
56 }),
57 Net::Connection->new({
58 'foreign_host' => '3.3.3.3',
59 'local_host' => '4.4.4.4',
60 'foreign_port' => '22',
61 'local_port' => '11132',
62 'sendq' => '1',
63 'recvq' => '0',
64 'state' => 'ESTABLISHED',
65 'proto' => 'tcp4'
66 }),
67 );
68
69 my $sorter=Net::Connection::Sort::state->new;
70
71 @objects=$sorter->sorter( \@objects );
72
73 print Dumper( \@objects );
74  
75 =head1 METHODS
76  
77 =head2 new
78  
79 This initiates the module.
80  
81 No arguments are taken and this will always succeed.
82  
83 my $sorter=Net::Connection::Sort::state->new;
84  
85 =cut
86  
87 1 ▶sub new{
Subroutine new: called CC=1 SCAR=0.0
Pod documented
88 1 my $self = {
89 };
90 1 bless $self;
91  
92 1 return $self;
93 }
94  
95 =head2 sorter
96  
97 This sorts the array of Net::Connection objects.
98  
99 One object is taken and that is a array of objects.
100  
101 @objects=$sorter->sorter( \@objects );
102
103 print Dumper( \@objects );
104  
105 =cut
106  
107 2 ▶sub sorter{
Subroutine sorter: called CC=3 SCAR=11.7
Pod documented
108 2 my $self=$_[0];
109 2 my @objects;
110 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
111 defined( $_[1] ) &&
112 ( ref($_[1]) eq 'ARRAY' )
113 ){
114 2 @objects=@{ $_[1] };
115 }else{
116 0 die 'The passed item is either not a array or undefined';
117 }
118  
119 @objects=sort {
120 2 $a->state cmp $b->state
121 } @objects;
122  
123 2 return @objects;
124 }
125  
126 =head1 AUTHOR
127  
128 Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
129  
130 =head1 BUGS
131  
132 Please report any bugs or feature requests to C<bug-net-connection-sort at rt.cpan.org>, or through
133 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Connection-Sort>. I will be notified, and then you'll
134 automatically be notified of progress on your bug as I make changes.
135  
136  
137  
138  
139 =head1 SUPPORT
140  
141 You can find documentation for this module with the perldoc command.
142  
143 perldoc Net::Connection::Sort
144  
145  
146 You can also look for information at:
147  
148 =over 4
149  
150 =item * RT: CPAN's request tracker (report bugs here)
151  
152 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Connection-Sort>
153  
154 =item * Search CPAN
155  
156 L<https://metacpan.org/release/Net-Connection-Sort>
157  
158 =item * Git Repo
159  
160 L<https://gitea.eesdp.org/vvelox/Net-Connection-Sort>
161  
162 =back
163  
164  
165 =head1 ACKNOWLEDGEMENTS
166  
167  
168 =head1 LICENSE AND COPYRIGHT
169  
170 This software is Copyright (c) 2019 by Zane C. Bowers-Hadley.
171  
172 This is free software, licensed under:
173  
174 The Artistic License 2.0 (GPL Compatible)
175  
176  
177 =cut
178  
179 2 1; # End of Net::Connection::Sort
« Sort/proto.pm ↑ Summary Sort/pid.pm »