annotate Lib/IMPL/Resources/Format.pm @ 164:eb3e9861a761

SQL traits in progress
author wizard
date Mon, 28 Mar 2011 01:36:24 +0400
parents e6447ad85cb4
children 4d0e1962161c
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 {
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 49
diff changeset
10 my ($string,$args,$resolver) = @_;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
11
148
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 104
diff changeset
12 $args ||= {};
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 49
diff changeset
13 $resolver ||= \&_defaultResolver;
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 49
diff changeset
14
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 49
diff changeset
15 $string =~ s/%(\w+(?:\.\w+)*)%/_getvalue($args,$1,"\[$1\]",$resolver)/ge;
49
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 return $string;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
18 }
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 sub _getvalue {
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 49
diff changeset
21 my ($obj,$path,$default,$resolver) = @_;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
22
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
23 foreach my $chunk (split /\./,$path) {
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 49
diff changeset
24 return $default unless $obj;
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 49
diff changeset
25 if (ref $obj eq 'HASH') {
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
26 $obj = $obj->{$chunk};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
27 } else {
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 49
diff changeset
28 $obj = $resolver->($obj,$chunk);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
29 }
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 return $obj;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
32 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
33
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 49
diff changeset
34 sub _defaultResolver {
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 49
diff changeset
35 my ($obj,$prop) = @_;
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 49
diff changeset
36
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 49
diff changeset
37 return ( eval { $obj->can($prop) } ? $obj->$prop() : undef );
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 49
diff changeset
38 }
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 49
diff changeset
39
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 18
diff changeset
40 1;