| 1 | package Net::Connection::Sort::user; | ||||||||||||||||||||||||||||
| 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::user - Sorts the connections via the username | ||||||||||||||||||||||||||||
| 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 username is not a requirement and if not specified is | ||||||||||||||||||||||||||||
| 23 | treated as a empty string, meaning it will show up earlier. | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | use Net::Connection::Sort::user; | ||||||||||||||||||||||||||||
| 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 | 'username' => 'toor', | ||||||||||||||||||||||||||||
| 42 | 'uid_resolve' => 0, | ||||||||||||||||||||||||||||
| 43 | }), | ||||||||||||||||||||||||||||
| 44 | Net::Connection->new({ | ||||||||||||||||||||||||||||
| 45 | 'foreign_host' => '1.1.1.1', | ||||||||||||||||||||||||||||
| 46 | 'local_host' => '2.2.2.2', | ||||||||||||||||||||||||||||
| 47 | 'foreign_port' => '22', | ||||||||||||||||||||||||||||
| 48 | 'local_port' => '11132', | ||||||||||||||||||||||||||||
| 49 | 'sendq' => '1', | ||||||||||||||||||||||||||||
| 50 | 'recvq' => '0', | ||||||||||||||||||||||||||||
| 51 | 'state' => 'ESTABLISHED', | ||||||||||||||||||||||||||||
| 52 | 'proto' => 'tcp4', | ||||||||||||||||||||||||||||
| 53 | 'uid' => 1000, | ||||||||||||||||||||||||||||
| 54 | 'pid' => 0, | ||||||||||||||||||||||||||||
| 55 | 'username' => 'root', | ||||||||||||||||||||||||||||
| 56 | 'uid_resolve' => 0, | ||||||||||||||||||||||||||||
| 57 | }), | ||||||||||||||||||||||||||||
| 58 | Net::Connection->new({ | ||||||||||||||||||||||||||||
| 59 | 'foreign_host' => '5.5.5.5', | ||||||||||||||||||||||||||||
| 60 | 'local_host' => '6.6.6.6', | ||||||||||||||||||||||||||||
| 61 | 'foreign_port' => '22', | ||||||||||||||||||||||||||||
| 62 | 'local_port' => '11132', | ||||||||||||||||||||||||||||
| 63 | 'sendq' => '1', | ||||||||||||||||||||||||||||
| 64 | 'recvq' => '0', | ||||||||||||||||||||||||||||
| 65 | 'state' => 'ESTABLISHED', | ||||||||||||||||||||||||||||
| 66 | 'proto' => 'tcp4', | ||||||||||||||||||||||||||||
| 67 | 'uid' => 1, | ||||||||||||||||||||||||||||
| 68 | 'pid' => 44, | ||||||||||||||||||||||||||||
| 69 | 'username' => 'foo', | ||||||||||||||||||||||||||||
| 70 | 'uid_resolve' => 0, | ||||||||||||||||||||||||||||
| 71 | }), | ||||||||||||||||||||||||||||
| 72 | # as no username is specified, a empty string will just be used instead | ||||||||||||||||||||||||||||
| 73 | Net::Connection->new({ | ||||||||||||||||||||||||||||
| 74 | 'foreign_host' => '3.3.3.3', | ||||||||||||||||||||||||||||
| 75 | 'local_host' => '4.4.4.4', | ||||||||||||||||||||||||||||
| 76 | 'foreign_port' => '22', | ||||||||||||||||||||||||||||
| 77 | 'local_port' => '11132', | ||||||||||||||||||||||||||||
| 78 | 'sendq' => '1', | ||||||||||||||||||||||||||||
| 79 | 'recvq' => '0', | ||||||||||||||||||||||||||||
| 80 | 'state' => 'ESTABLISHED', | ||||||||||||||||||||||||||||
| 81 | 'proto' => 'tcp4', | ||||||||||||||||||||||||||||
| 82 | }), | ||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | my $sorter=Net::Connection::Sort::user->new; | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | @objects=$sorter->sorter( \@objects ); | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | print Dumper( \@objects ); | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =head1 METHODS | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =head2 new | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | This initiates the module. | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | No arguments are taken and this will always succeed. | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | my $sorter=Net::Connection::Sort::user->new; | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =cut | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 1 | ▶ | sub new{ | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 104 | 1 | my $self = { | |||||||||||||||||||||||||||
| 105 | }; | ||||||||||||||||||||||||||||
| 106 | 1 | bless $self; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 1 | return $self; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | =head2 sorter | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | This sorts the array of Net::Connection objects. | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | One object is taken and that is a array of objects. | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | @objects=$sorter->sorter( \@objects ); | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | print Dumper( \@objects ); | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | =cut | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 2 | ▶ | sub sorter{ | ||||||||||||||||||||||||||
|
Subroutine
sorter: called CC=3 SCAR=11.7
Pod
documented
| |||||||||||||||||||||||||||||
| 124 | 2 | my $self=$_[0]; | |||||||||||||||||||||||||||
| 125 | 2 | my @objects; | |||||||||||||||||||||||||||
| 126 | 2 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $_[1] and ref $_[1] eq "ARRAY"
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"
| |||||||||||||||||||||||||||||
| 127 | defined( $_[1] ) && | ||||||||||||||||||||||||||||
| 128 | ( ref($_[1]) eq 'ARRAY' ) | ||||||||||||||||||||||||||||
| 129 | ){ | ||||||||||||||||||||||||||||
| 130 | 2 | @objects=@{ $_[1] }; | |||||||||||||||||||||||||||
| 131 | }else{ | ||||||||||||||||||||||||||||
| 132 | 0 | die 'The passed item is either not a array or undefined'; | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | @objects=sort { | ||||||||||||||||||||||||||||
| 136 | 2 | helper( $a->username ) cmp helper( $b->username ) | |||||||||||||||||||||||||||
| 137 | } @objects; | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 2 | return @objects; | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | =head2 helper | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | This is a internal function. | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | If no username is defined, returns a empty string. This is compared using | ||||||||||||||||||||||||||||
| 147 | cmp, so a empty string is used instead of 0 to keep it from colliding with a | ||||||||||||||||||||||||||||
| 148 | user actually named 0. | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | =cut | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 10 | ▶ | sub helper{ | ||||||||||||||||||||||||||
|
Subroutine
helper: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 153 | 10 | ▶ | if ( !defined($_[0]) ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | 3 | return ''; | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | 7 | return $_[0]; | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >> | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | =head1 BUGS | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | Please report any bugs or feature requests to C<bug-net-connection-sort at rt.cpan.org>, or through | ||||||||||||||||||||||||||||
| 166 | the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Connection-Sort>. I will be notified, and then you'll | ||||||||||||||||||||||||||||
| 167 | automatically be notified of progress on your bug as I make changes. | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | perldoc Net::Connection::Sort | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | You can also look for information at: | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | =over 4 | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | =item * RT: CPAN's request tracker (report bugs here) | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Connection-Sort> | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | =item * Search CPAN | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | L<https://metacpan.org/release/Net-Connection-Sort> | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | =item * Git Repo | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | L<https://gitea.eesdp.org/vvelox/Net-Connection-Sort> | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | =back | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | This software is Copyright (c) 2019 by Zane C. Bowers-Hadley. | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | This is free software, licensed under: | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | The Artistic License 2.0 (GPL Compatible) | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | =cut | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 2 | 1; # End of Net::Connection::Sort | |||||||||||||||||||||||||||