1 #**************************************************************************
2 # Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu> *
4 # This program is free software; you can redistribute it and/or modify *
5 # it under the terms of the GNU General Public License as published by *
6 # the Free Software Foundation; either version 2 of the License, or *
7 # (at your option) any later version. *
9 # This program is distributed in the hope that it will be useful, *
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 # GNU General Public License for more details. *
14 # You should have received a copy of the GNU General Public License *
15 # along with this program; if not, write to the *
16 # Free Software Foundation, Inc., *
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 #**************************************************************************/
26 our @ISA = qw/Exporter/;
28 our @EXPORT = qw/parseStats/;
30 my %classes = (Fighter => 'Fi', Corvette => 'Co', Frigate => 'Fr', Destroyer => 'De', Cruiser => 'Cr', Battleship => 'Bs', Structure => 'St', Roids => 'Ro', Resources => 'Re', '-' => '-');
36 my $parser = XML::LibXML->new();
37 my $xmldoc = $parser->parse_string($xml);
39 for my $sample ( $xmldoc->findnodes('/stats/ship') ) {
41 for my $child ( $sample->getChildnodes ) {
42 if ( $child->nodeType() == XML_ELEMENT_NODE ) {
43 my $nodeName = $child->nodeName();
44 $nodeName = 'ship' if $nodeName eq 'name';
45 $nodeName = 'init' if $nodeName eq 'initiative';
46 $nodeName = 'eres' if $nodeName eq 'empres';
47 my $text = $child->textContent();
48 $text = $classes{$text} if $nodeName eq 'class';
49 $text = 0 if $text eq '-' && $nodeName eq 'damage';
50 if ($nodeName =~ /^target(\d+)$/) {
52 $text = $classes{$text};
54 $ship{$nodeName} = $text;