aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAngelo Naselli <anaselli@linux.it>2016-01-02 22:53:37 +0100
committerAngelo Naselli <anaselli@linux.it>2016-01-02 22:53:37 +0100
commit470ad65745ae6ca58c7620dfa56e5a4b7167b9cd (patch)
tree0084c4bd15ecd0d542be58f4bd8876f014fc6f6d /lib
parentafd142d7ec5daeee883de5494f52ab129efe5be8 (diff)
downloadmanatools-470ad65745ae6ca58c7620dfa56e5a4b7167b9cd.tar
manatools-470ad65745ae6ca58c7620dfa56e5a4b7167b9cd.tar.gz
manatools-470ad65745ae6ca58c7620dfa56e5a4b7167b9cd.tar.bz2
manatools-470ad65745ae6ca58c7620dfa56e5a4b7167b9cd.tar.xz
manatools-470ad65745ae6ca58c7620dfa56e5a4b7167b9cd.zip
Reading xml:lang attribute for lang and building a convenient hash
Diffstat (limited to 'lib')
-rw-r--r--lib/ManaTools/ConfigReader.pm61
1 files changed, 25 insertions, 36 deletions
diff --git a/lib/ManaTools/ConfigReader.pm b/lib/ManaTools/ConfigReader.pm
index b3c6181f..b189a05d 100644
--- a/lib/ManaTools/ConfigReader.pm
+++ b/lib/ManaTools/ConfigReader.pm
@@ -121,25 +121,20 @@ has 'data' => (
sub _dataInitialize {
my $self = shift;
- my $xml = new XML::Simple (KeyAttr=>[]);
- my $data = $xml->XMLin($self->fileName());
- if (ref($data->{category}) eq "HASH") {
- # one element alone
- my @categories;
- push @categories, $data->{category};
- $data->{category} = undef;
- push @{$data->{category}}, @categories;
- }
+ my $xml = new XML::Simple ();
+ my $data = $xml->XMLin(
+ $self->fileName(),
+ ContentKey => '-content',
+ ForceArray => ['category', 'title', 'module'],
+ KeyAttr=>{
+ title => "xml:lang",
+ }
+ );
$self->catLen( scalar(@{$data->{category}}) );
-
- if(ref(@{$data->{category}}[0]->{module}) eq "ARRAY") {
- $self->modLen(
- scalar(@{@{$data->{category}}[0]->{module}})
- );
- } else {
- $self->modLen(1);
- }
+ $self->modLen(
+ scalar(@{@{$data->{category}}[0]->{module}})
+ );
return $data;
}
@@ -234,24 +229,20 @@ sub hasNextCat {
sub getNextCat {
my $self = shift;
- $self->currCat($self->currCat()+1);
- if($self->currCat() >= $self->catLen()) {
- return 0;
- }
-
- # Reset the Module Count and Mod length for new Category
- $self->currMod(-1);
- if(ref(@{$self->data()->{category}}[$self->currCat()]->{module}) eq "ARRAY") {
+ if ($self->hasNextCat()) {
+ $self->currCat($self->currCat()+1);
+ # Reset the Module Count and Mod length for new Category
+ $self->currMod(-1);
$self->modLen(
scalar(@{@{$self->data()->{category}}[$self->currCat()]->{module}})
);
- } else {
- $self->modLen(1);
- }
- my $cat = @{$self->data()->{category}}[$self->currCat()];
+ my $cat = @{$self->data()->{category}}[$self->currCat()];
- return $cat;
+ return $cat;
+ }
+
+ return;
}
#=============================================================
@@ -306,15 +297,13 @@ sub getNextMod {
my $ret = 0;
- $self->currMod($self->currMod()+1);
-
- if($self->{modLen} == 1) {
- $ret = @{$self->data()->{category}}[$self->currCat()]->{module};
- } else {
+ if ($self->hasNextMod()) {
+ $self->currMod($self->currMod()+1);
$ret = @{@{$self->data()->{category} }[$self->currCat()]->{module}}[$self->currMod()];
+ return $ret;
}
- return $ret;
+ return;
}
no Moose;