annotate Lib/IMPL/Resources/Strings.pm @ 46:75148ccd732d

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