1package Nmap::Scanner::PortList;
2
3use strict;
4
5sub new {
6    my $class = shift;
7    my $me = { TCP => shift, UDP => shift };
8
9    my @tcpkeys = sort { $a <=> $b } keys %{$me->{TCP}};
10    my @udpkeys = sort { $a <=> $b } keys %{$me->{UDP}};
11    $me->{UDPKEYS} = \@udpkeys;
12    $me->{TCPKEYS} = \@tcpkeys;
13
14    return bless $me, $class;
15}
16
17sub get_next_tcp {
18    return $_[0]->{TCP}->{shift @{$_[0]->{TCPKEYS}}}
19        if @{$_[0]->{TCPKEYS}};
20}
21
22sub get_next_udp {
23    return $_[0]->{UDP}->{shift @{$_[0]->{UDPKEYS}}}
24        if @{$_[0]->{UDPKEYS}};
25}
26
27sub get_next {
28    return $_[0]->get_next_tcp() || $_[0]->get_next_udp();
29}
30
31sub as_xml {
32    my $self = shift;
33
34    my $xml;
35
36    while (my $p = $self->get_next()) {
37        last unless defined $p;
38        $xml .= $p->as_xml() . "\n";
39    }
40
41    return $xml;
42
43}
44
451;
46
47=pod
48
49=head2 DESCRIPTION
50
51Holds a list of Nmap::Scanner::Port
52objects.  get_next() returns a port
53reference while there are ports in
54the list and returns undef when
55the list is exhausted.  Port lists are
56sorted internally by port number.
57
58get_next_tcp() and get_next_udp() will
59return the next port of either protocol;
60get_next() returns first tcp then udp.
61
62=cut
63