1package Nmap::Scanner::HostList; 2 3use strict; 4 5sub new { 6 my $class = shift; 7 my $me = { LISTREF => shift }; 8 9 my @keys = sort keys %{$me->{LISTREF}}; 10 $me->{KEYS} = \@keys; 11 12 return bless $me, $class; 13} 14 15sub get_next { 16 return $_[0]->{LISTREF}->{ shift @{$_[0]->{KEYS}} } 17 if @{$_[0]->{KEYS}}; 18} 19 20sub as_xml { 21 22 my $self = shift; 23 24 my $xml; 25 26 while (my $host = $self->get_next()) { 27 last unless defined $host; 28 $xml .= $host->as_xml(); 29 } 30 31 return $xml; 32 33} 34 351; 36 37=pod 38 39=head2 DESCRIPTION 40 41Holds a list of Nmap::Scanner::Host 42objects. get_next() returns a host 43reference while there are hosts in 44the list and returns undef when 45the list is exhausted. Hosts are 46indexed and sorted internally by primary 47IP address. 48 49=head2 get_next() 50 51Return the next Nmap::Scanner::Host from the list, or 52undef if the list is empty. 53 54=head2 as_xml() 55 56Returns an XML string representation of all hosts in the list. 57 58=cut 59