summaryrefslogtreecommitdiffstats
path: root/modules/xml.pl
diff options
context:
space:
mode:
Diffstat (limited to 'modules/xml.pl')
-rw-r--r--modules/xml.pl39
1 files changed, 39 insertions, 0 deletions
diff --git a/modules/xml.pl b/modules/xml.pl
new file mode 100644
index 0000000..2cb2505
--- /dev/null
+++ b/modules/xml.pl
@@ -0,0 +1,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;