annotate Lib/IMPL/Resources/Strings.pm @ 54:f4e045e47770

commit
author wizard@linux-odin.local
date Tue, 02 Mar 2010 20:15:57 +0300
parents 521c9c1a3ea1
children f47f93534005
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: 46
diff changeset
1 use strict;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
2 use warnings;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
3
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
4 package IMPL::Resources::Strings::Storage;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
5 package IMPL::Resources::Strings;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
6 use File::Spec;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
7
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
8 our $Locale ||= 'default';
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
9 our $Base ||='locale';
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
10 our $Encoding ||= 'utf-8';
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
11 our @Locations;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
12
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
13 @Locations = ('.') unless @Locations;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
14
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
15 sub import {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
16 my ($self,$refStrings,%options) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
17
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
18 my ($class,$pathModule) = caller;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
19
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
20 my ($vol,$dir,$file) = File::Spec->splitpath($pathModule);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
21 my $baseDir = File::Spec->catpath($vol,$dir,'');
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
22
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
23 my @pathClass = split /::/,$class;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
24 my $fileClass = pop @pathClass;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
25
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
26 my @ways = map {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
27 my @path = ($_);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
28 push @path,$Base;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
29 push @path,$Locale;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
30
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
31 File::Spec->catfile(@path,@pathClass,$fileClass);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
32 } @Locations;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
33
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
34 push @ways, File::Spec->catfile($baseDir,'locale',$Locale,$fileClass);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
35
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
36
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
37
50
wizard@linux-odin.local
parents: 49
diff changeset
38 my $stringsStorage = findResource($class,@ways);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
39
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
40 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
41
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
42 sub findResource {
50
wizard@linux-odin.local
parents: 49
diff changeset
43 my ($class,$refWays) = @_;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
44
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
45
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
46 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
47
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
48
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
50 sub parseResource {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
51 my ($fname) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
52
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
53 open my $hRes, "<:encoding($Encoding)", findFile($fname) or die "Failed to open file $fname: $!";
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
54
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
55 my %Map;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
56 my $line = 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
57 while (<$hRes>) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
58 chomp;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
59 $line ++ and next if /^\s*$/;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
60
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
61 if (/^(\w+)\s*=\s*(.*)$/) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
62 $Map{$1} = $2;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
63 } else {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
64 die "Invalid resource format in $fname at $line";
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
65 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
66 $line ++;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
67 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
68
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
69 return \%Map;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
70 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
71
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
72 package IMPL::Resources::Strings::Storage;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
73 use base qw(IMPL::Object);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
74
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
75 sub get {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
76 my ($this,$msg_name) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
77 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
78 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
79
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
80 __END__
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
81
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
82 =pod
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
83
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
84 =head1 SYNOPSIS
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
85
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
86 package Foo;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
87
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
88 use IMPL::Resources::Strings {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
89 msg_say_hello => "Hello, %name!",
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
90 msg_module_name => "Simple Foo class"
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
91 }, auto => 1, locale => 'en-us';
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
92
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
93 sub InviteUser {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
94 my ($this,$uname) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
95
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
96 print msg_say_hello(name => $uname);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
97
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
98 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
99
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
100 =cut