Sort.pm

filter: Statementstmt 32.2% 10 / 31 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 3 / 5 Podpod 100% 2 / 2 totaltotal 30.0% 15 / 50 CC 7 SCAR 31.9
CC
7
Cov
23%
new
42.0
sorter
6.0
BEGIN
1.0
CRAP 24.3
↑ Summary Sort/host_fl.pm »
1 package Net::Connection::Sort;
2  
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 NAME
8  
9 Net::Connection::Sort - Sorts array of Net::Connection objects.
10  
11 =head1 VERSION
12  
13 Version 0.0.1
14  
15 =cut
16  
17 1 our $VERSION = '0.0.1';
18  
19  
20 =head1 SYNOPSIS
21  
22 use Net::Connection::Sort;
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' => 'ESTABLISHED',
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' => 'ESTABLISHED',
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' => 'ESTABLISHED',
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 $sort_args={
70 type=>'host_f',
71 invert=>0,
72 };
73
74 my $mcs;
75 eval{
76 $mcs=Net::Connection::Sort->new( $sort_args );
77 };
78
79 if ( ! defined( $mcs ) ){
80 print "Failed to init the sorter... ".$@;
81 }
82
83 my @sorted=$mcs->sorter( \@objects );
84
85 print Dumper( \@sorted );
86  
87 =head1 METHODS
88  
89 =head2 new
90  
91 This initiates the module.
92  
93 One argument is taken and that is a hash ref with two possible keys,
94 'type' and 'invert'. If not passed or any of the keys are undef, then
95 the defaults will be used.
96  
97 'type' is the module to use. It is relative to 'Net::Connection::Sort',
98 so 'host_f' becomes 'Net::Connection::Sort::host_f'.
99  
100 my $sort_args={
101 type=>'host_f',
102 invert=>0,
103 };
104
105 my $mcs;
106 eval{
107 $ncs=Net::Connection::Sort->new( $sort_args );
108 };
109
110 if ( ! defined( $mcs ) ){
111 print "Failed to init the sorter... ".$@;
112 }
113  
114 =cut
115  
116 sub new{
117 0 ▶ my %args;
Subroutine new: not called CC=6 SCAR=37.4
Pod documented
118 0 ▶ if(defined($_[1])){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) 0 0 0
119 0 %args= %{$_[1]};
120 };
121  
122  
123 0 my $self = {
124 testing=>0,
125 type=>'host_f',
126 invert=>0,
127 sorter=>undef,,
128 };
129 0 bless $self;
130  
131 # real in the args if needed
132 0 ▶ if (defined( $args{type} )){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"type"}) 0 0 0
133 0 $self->{type}=$args{type};
134 }
135 0 ▶ if (defined( $args{invert} )){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"invert"}) 0 0 0
136 0 $self->{invert}=$args{invert};
137 }
138  
139 # see of we amd reel in the module
140 my $to_eval='use Net::Connection::Sort::'.$self->{type}
141 0 .'; $self->{sorter}=Net::Connection::Sort::'.$self->{type}.'->new;';
142 0 ▶ eval( $to_eval ) or die('Failed to use or invoke Net::Connection::Sort::'.$self->{type}.'->new... '.$@);
Branch: 1 branch
BranchTrueFalseTotal
eval $to_eval or die 'Failed to use or invoke Net::Connection::Sort::' . $self->{"type"} . '->new... ' . $@ 0 0 0
143  
144 # make sure we did get it
145 0 ▶ if (!defined( $self->{sorter} )){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"sorter"}) 0 0 0
146 0 die( 'Net::Connection::Sort::'.$self->{type}.'->new returned undef');
147 }
148  
149 0 return $self;
150 }
151  
152 =head2 sorter
153  
154 This sorts the array of Net::Connection objects.
155  
156 One object is taken and that is a array of objects.
157  
158 my @sorted=$mcs->sorter( \@objects );
159
160 print Dumper( \@sorted );
161  
162 =cut
163  
164 sub sorter{
165 0 ▶ my $self=$_[0];
Subroutine sorter: not called CC=2 SCAR=17.9
Pod documented
166 0 my @objects;
167 0 ▶ if(defined($_[1])){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) 0 0 0
168 0 @objects= @{$_[1]};
169 };
170  
171 0 return $self->{sorter}->sorter( \@objects );
172 }
173  
174 =head1 AUTHOR
175  
176 Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
177  
178 =head1 BUGS
179  
180 Please report any bugs or feature requests to C<bug-net-connection-sort at rt.cpan.org>, or through
181 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Connection-Sort>. I will be notified, and then you'll
182 automatically be notified of progress on your bug as I make changes.
183  
184  
185  
186  
187 =head1 SUPPORT
188  
189 You can find documentation for this module with the perldoc command.
190  
191 perldoc Net::Connection::Sort
192  
193  
194 You can also look for information at:
195  
196 =over 4
197  
198 =item * RT: CPAN's request tracker (report bugs here)
199  
200 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Connection-Sort>
201  
202 =item * AnnoCPAN: Annotated CPAN documentation
203  
204 L<http://annocpan.org/dist/Net-Connection-Sort>
205  
206 =item * CPAN Ratings
207  
208 L<https://cpanratings.perl.org/d/Net-Connection-Sort>
209  
210 =item * Search CPAN
211  
212 L<https://metacpan.org/release/Net-Connection-Sort>
213  
214 =item * Git Repo
215  
216 L<https://gitea.eesdp.org/vvelox/Net-Connection-Sort>
217  
218 =back
219  
220  
221 =head1 ACKNOWLEDGEMENTS
222  
223  
224 =head1 LICENSE AND COPYRIGHT
225  
226 This software is Copyright (c) 2019 by Zane C. Bowers-Hadley.
227  
228 This is free software, licensed under:
229  
230 The Artistic License 2.0 (GPL Compatible)
231  
232  
233 =cut
234  
235 1 1; # End of Net::Connection::Sort
↑ Summary Sort/host_fl.pm »