# HG changeset patch # User sergey # Date 1390430128 -14400 # Node ID 99ac2e19c0cc057580647859bd4e643c7c33dadb # Parent ced5937ff21a3c52c034af98d71e0747e5d4405a Implemented a strings map for a DOM schema diff -r ced5937ff21a -r 99ac2e19c0cc Lib/IMPL/DOM/Schema.pm --- a/Lib/IMPL/DOM/Schema.pm Wed Jan 22 16:56:10 2014 +0400 +++ b/Lib/IMPL/DOM/Schema.pm Thu Jan 23 02:35:28 2014 +0400 @@ -80,9 +80,17 @@ sub _getStringMap { my ($this) = @_; - + return $this->{$stringMap} + if return $this->{$stringMap}; + + my $map = StringMap->new(); + if ($this->baseDir and $this->schemaName) { + + $map->paths( File::Spec->catdir($this->baseDir,'locale') ); + $map->name(schemaName); + } - File::Spec->catdir($this->baseDir,'locale'); + return $this->{$stringMap} = $map; } sub Process { diff -r ced5937ff21a -r 99ac2e19c0cc Lib/IMPL/Resources/StringLocaleMap.pm --- a/Lib/IMPL/Resources/StringLocaleMap.pm Wed Jan 22 16:56:10 2014 +0400 +++ b/Lib/IMPL/Resources/StringLocaleMap.pm Thu Jan 23 02:35:28 2014 +0400 @@ -28,6 +28,10 @@ $this->_maps({ default => $data }); } elsif ( ref($data) eq 'HASH' ) { $this->_maps({ default => StringMap->new($data,$parent)}); + } else { + # в данном случае таблица строк по-умолчанию будет загружена + # из файла при необходимости + $this->_maps({}); } } @@ -37,16 +41,17 @@ my $locale = Resources->currentLocale || 'default'; my $map; - warn "id: $id,\t\tlocale: $locale"; + #warn "id: $id,\t\tlocale: $locale"; if(not $map = $this->_maps->{$locale}) { - $map = $this->LoadMap($locale,$this->_maps->{default}); + my $default = $this->GetDefaultMap(); + $map = $this->LoadMap($locale,$default); if (is($map,StringMap)) { #nop } elsif (ref($map) eq 'HASH') { - $map = StringMap->new($map,$this->_maps->{default}); + $map = StringMap->new($map,$default); } elsif( not $map ) { - $map = $this->_maps->{default}; + $map = $default; } else { die Exception->new("ResolveLocale returned unexpected data", $map); } @@ -57,6 +62,19 @@ return $map->GetString($id,$args); } +sub GetDefaultMap { + my ($this) = @_; + + my $map = $this->_maps->{default}; + return $map + if $map; + + $map = $this->LoadMap('default') || StringMap->new({}); + $this->_maps->{default} = $map; + + return $map; +} + sub LoadMap { my ($this,$locale,$default) = @_; diff -r ced5937ff21a -r 99ac2e19c0cc _test/Test/DOM/Node.pm --- a/_test/Test/DOM/Node.pm Wed Jan 22 16:56:10 2014 +0400 +++ b/_test/Test/DOM/Node.pm Thu Jan 23 02:35:28 2014 +0400 @@ -207,10 +207,11 @@ test listNodePredefinedProps => sub { my $node = Test::DOM::TypedNode->new(nodeName => 'TestNode'); + # the order of properties is not defined my @props = $node->listProperties; my @expected = qw(name _private); - failed "Got wrong list of props", @props unless cmparray(\@props,\@expected); + failed "Got wrong list of props", @props unless cmparray([sort @props],[sort @expected]); }; test listNodeAllProps => sub { @@ -224,7 +225,7 @@ my @props = $node->listProperties; my @expected = qw(name _private uuid); # systemName is not a DOM prop - failed "Got wrong list of props", @props unless cmparray(\@props,\@expected); + failed "Got wrong list of props", @props unless cmparray([sort @props],[sort @expected]); }; test MemoryLeaks => sub {