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

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