summaryrefslogtreecommitdiffstats
path: root/modules/xml.pl
blob: 2cb2505af9572bbc75a6fbf193670be281d2fa4f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use warnings;
use strict;

use XML::Simple qw(:strict);

my $xs1 = XML::Simple->new( KeyAttr => ['id'], Cache => [ qw/storable memcopy/ ]);

sub readXML {
  my ( $p ) = $::cset; #@_;
  $p = 'default' if $p eq '';
  $p = "config-$p";
  $::settings = $xs1->XMLin( "$p/settings.xml", ForceArray => [qw/host/],
                           GroupTags  => { altnicks => 'altnick', server => 'host', autojoins=> 'autojoin' });
  $::channels = $xs1->XMLin( "$p/channels.xml", ForceArray => [qw/event debug info low medium high/] );
  $::users    = $xs1->XMLin( "$p/users.xml",    ForceArray => 'person' );
  $::xusers   = $::users->{person};
  $::commands = $xs1->XMLin( "$p/commands.xml", ForceArray => [qw/command/]);
}

sub writeXML {
  my ( $p ) = @_;
  $p = 'default' if $p eq '';
  $p = "config-$p";
  $xs1->XMLout($::settings, RootName => 'settings', KeyAttr => ['id'],
               GroupTags => { altnicks => 'altnick', server => 'host', autojoins => 'autojoin' },
               ValueAttr => { debug => 'content',     nick => 'content',    port => 'content',
                           realname => 'content', username => 'content',     dir => 'content',
                               zone => 'content',  filefmt => 'content', timefmt => 'content'}) > io("$p/settings.xml");
  $xs1->XMLout($::channels, RootName => 'channels', KeyAttr => ['id']) > io("$p/channels.xml");
  $xs1->XMLout($::users,    RootName => 'people',   KeyAttr => ['id']) > io("$p/users.xml");
  $xs1->XMLout($::commands, RootName => 'commands', KeyAttr => ['id']) > io("$p/commands.xml");
}

sub Xml::killsub {
  undef &readXML;
  undef &writeXML;
}

return 1;