Mercurial > pub > Impl
diff Lib/IMPL/Resources/StringMap.pm @ 378:2eed076cb944
rewritten IMPL::Resources::Strings + tests
author | cin |
---|---|
date | Wed, 15 Jan 2014 17:20:54 +0400 |
parents | a0d342ac9a36 |
children | ced5937ff21a |
line wrap: on
line diff
--- a/Lib/IMPL/Resources/StringMap.pm Tue Jan 14 20:06:36 2014 +0400 +++ b/Lib/IMPL/Resources/StringMap.pm Wed Jan 15 17:20:54 2014 +0400 @@ -1,4 +1,4 @@ -package IMPL::Web::Resources::StringMap; +package IMPL::Resources::StringMap; use strict; use IMPL::Const qw(:prop); @@ -8,6 +8,9 @@ IOException => '-IMPL::IOException', ArgException => '-IMPL::InvalidArgumentException' }, + base => [ + 'IMPL::Object' => '@_' + ], props => [ _data => PROP_RW, _parent => PROP_RW @@ -21,7 +24,7 @@ unless ref($data) eq 'HASH'; die ArgException->new( data => 'A hash must contain either scalars or subs') - if ref($_) && ref($_) ne 'CODE', values %$data; + if grep ref($_) && ref($_) ne 'CODE', values %$data; $this->_data($data); $this->_parent($parent); @@ -31,7 +34,7 @@ my ($this,$id,$args) = @_; if(my $format = $this->_data->{$id}) { - return $this->FormatString($format,$args); + return ref($format) eq 'CODE' ? &$format($this,$args || {}) : $this->FormatString($format,$args); } else { return $this->_parent? $this->_parent->GetString($id,$args) : "[ $id ]"; } @@ -54,12 +57,11 @@ my ($self,$text,$args) = @_; $args ||= {}; - $resolver ||= \&_defaultResolver; $text ||= ''; - $string =~ s/%(\w+(?:\.\w+)*)%/$self->GetValue($args,$1,"\[$1\]")/ge; + $text =~ s/%(\w+(?:\.\w+)*)%/$self->GetValue($args,$1,"\[$1\]")/ge; - return $string; + return $text; } @@ -83,18 +85,6 @@ return ( eval { $obj->can($prop) } ? $obj->$prop() : undef ); } -sub _LoadMap { - my ($self,$file,$parent) = @_; - - my $data = do $file; - my $e = $@; - die Exception->new("Failed to load file '$file'", $e) if $e; - die IOException->new("Failed to load file '$file'", $!) if not defined $data and $!; - die Exception->new("Failed to load file '$file'", "A hash data is expected") unless ref($data) eq 'HASH'; - - return $self->new($data,$parent); -} - 1; __END__