annotate Lib/IMPL/Resources/Format.pm @ 58:a35b60b16a99

Configuration, late activation
author wizard
date Fri, 05 Mar 2010 20:14:45 +0300
parents 16ada169ca75
children 196bf443b5e1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
1 package IMPL::Resources::Format;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
2 use strict;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
3 use warnings;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
4
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
5 require Exporter;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
6 our @ISA = qw(Exporter);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
7 our @EXPORT_OK = qw(&FormatMessage);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
8
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
9 sub FormatMessage {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
10 my ($string,$args) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
11
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
12 $string =~ s/%(\w+(?:\.\w+)*)%/_getvalue($args,$1,"\[$1\]")/ge;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
13
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
14 return $string;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
15 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
16
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
17 sub _getvalue {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
18 my ($obj,$path,$default) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
19
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
20 foreach my $chunk (split /\./,$path) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
21 if (eval { $obj->can( $chunk ) } ) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
22 $obj = $obj->$chunk();
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
23 } elsif (UNIVERSAL::isa($obj,'HASH')) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
24 $obj = $obj->{$chunk};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
25 } else {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
26 return $default;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
27 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
28 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
29 return $obj;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
30 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
31
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
32 1;