49
|
1 package IMPL::Resources::Format;
|
|
2 use strict;
|
|
3 use warnings;
|
|
4
|
|
5 require Exporter;
|
|
6 our @ISA = qw(Exporter);
|
|
7 our @EXPORT_OK = qw(&FormatMessage);
|
|
8
|
|
9 sub FormatMessage {
|
|
10 my ($string,$args) = @_;
|
|
11
|
|
12 $string =~ s/%(\w+(?:\.\w+)*)%/_getvalue($args,$1,"\[$1\]")/ge;
|
|
13
|
|
14 return $string;
|
|
15 }
|
|
16
|
|
17 sub _getvalue {
|
|
18 my ($obj,$path,$default) = @_;
|
|
19
|
|
20 foreach my $chunk (split /\./,$path) {
|
|
21 if (eval { $obj->can( $chunk ) } ) {
|
|
22 $obj = $obj->$chunk();
|
|
23 } elsif (UNIVERSAL::isa($obj,'HASH')) {
|
|
24 $obj = $obj->{$chunk};
|
|
25 } else {
|
|
26 return $default;
|
|
27 }
|
|
28 }
|
|
29 return $obj;
|
|
30 }
|
|
31
|
|
32 1;
|