line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Rose::HTML::Object::Message::Localized; |
2
|
|
|
|
|
|
|
|
3
|
43
|
|
|
43
|
|
308
|
use strict; |
|
43
|
|
|
|
|
110
|
|
|
43
|
|
|
|
|
1319
|
|
4
|
|
|
|
|
|
|
|
5
|
43
|
|
|
43
|
|
226
|
use Carp; |
|
43
|
|
|
|
|
115
|
|
|
43
|
|
|
|
|
2276
|
|
6
|
43
|
|
|
43
|
|
330
|
use Rose::HTML::Object::Message::Localizer; |
|
43
|
|
|
|
|
112
|
|
|
43
|
|
|
|
|
1078
|
|
7
|
|
|
|
|
|
|
|
8
|
43
|
|
|
43
|
|
244
|
use base 'Rose::HTML::Object::Message'; |
|
43
|
|
|
|
|
99
|
|
|
43
|
|
|
|
|
20954
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.600'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
#our $Debug = 0; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use overload |
15
|
|
|
|
|
|
|
( |
16
|
2205
|
|
|
2205
|
|
35928
|
'""' => sub { shift->localized_text }, |
17
|
108
|
|
|
108
|
|
335
|
'bool' => sub { 1 }, |
18
|
0
|
|
|
0
|
|
0
|
'0+' => sub { 1 }, |
19
|
43
|
|
|
|
|
382
|
fallback => 1, |
20
|
43
|
|
|
43
|
|
308
|
); |
|
43
|
|
|
|
|
96
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
use Rose::Class::MakeMethods::Generic |
23
|
|
|
|
|
|
|
( |
24
|
43
|
|
|
|
|
301
|
inheritable_scalar => |
25
|
|
|
|
|
|
|
[ |
26
|
|
|
|
|
|
|
'_default_localizer', |
27
|
|
|
|
|
|
|
'default_locale', |
28
|
|
|
|
|
|
|
], |
29
|
43
|
|
|
43
|
|
4218
|
); |
|
43
|
|
|
|
|
109
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
__PACKAGE__->default_locale('en'); |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
1
|
0
|
6
|
sub generic_object_class { 'Rose::HTML::Object' } |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub localized_text |
36
|
|
|
|
|
|
|
{ |
37
|
2211
|
|
|
2211
|
1
|
3857
|
my($self) = shift; |
38
|
|
|
|
|
|
|
|
39
|
2211
|
|
|
|
|
4828
|
my $localizer = $self->localizer; |
40
|
|
|
|
|
|
|
|
41
|
2211
|
|
|
|
|
5667
|
return $localizer->localize_message( |
42
|
|
|
|
|
|
|
message => $self, |
43
|
|
|
|
|
|
|
parent => $self->parent, |
44
|
|
|
|
|
|
|
locale => $self->locale, |
45
|
|
|
|
|
|
|
variant => $self->variant, |
46
|
|
|
|
|
|
|
args => scalar $self->args); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub localizer |
50
|
|
|
|
|
|
|
{ |
51
|
2212
|
|
|
2212
|
1
|
3642
|
my($invocant) = shift; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Called as object method |
54
|
2212
|
50
|
|
|
|
5495
|
if(my $class = ref $invocant) |
55
|
|
|
|
|
|
|
{ |
56
|
2212
|
50
|
|
|
|
4815
|
if(@_) |
57
|
|
|
|
|
|
|
{ |
58
|
0
|
|
|
|
|
0
|
return $invocant->{'localizer'} = shift; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
2212
|
|
|
|
|
4114
|
my $localizer = $invocant->{'localizer'}; |
62
|
|
|
|
|
|
|
|
63
|
2212
|
50
|
|
|
|
4570
|
unless($localizer) |
64
|
|
|
|
|
|
|
{ |
65
|
2212
|
100
|
|
|
|
5533
|
if(my $parent = $invocant->parent) |
66
|
|
|
|
|
|
|
{ |
67
|
2206
|
50
|
|
|
|
5716
|
if(my $localizer = $parent->localizer) |
68
|
|
|
|
|
|
|
{ |
69
|
2206
|
|
|
|
|
93923
|
return $localizer; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
6
|
|
|
|
|
15
|
else { return $class->default_localizer } |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
0
|
|
|
0
|
return $localizer || $class->default_localizer; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
else # Called as class method |
78
|
|
|
|
|
|
|
{ |
79
|
0
|
0
|
|
|
|
0
|
if(@_) |
80
|
|
|
|
|
|
|
{ |
81
|
0
|
|
|
|
|
0
|
return $invocant->default_localizer(shift); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
0
|
return $invocant->default_localizer; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub default_localizer |
89
|
|
|
|
|
|
|
{ |
90
|
7
|
|
|
7
|
1
|
13
|
my($class) = shift; |
91
|
|
|
|
|
|
|
|
92
|
7
|
50
|
|
|
|
15
|
if(@_) |
93
|
|
|
|
|
|
|
{ |
94
|
0
|
|
|
|
|
0
|
return $class->_default_localizer(@_); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
7
|
100
|
|
|
|
20
|
if(my $localizer = $class->_default_localizer) |
98
|
|
|
|
|
|
|
{ |
99
|
6
|
|
|
|
|
54
|
return $localizer; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
1
|
|
|
|
|
42
|
return $class->_default_localizer($class->generic_object_class->localizer); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub locale |
106
|
|
|
|
|
|
|
{ |
107
|
2215
|
|
|
2215
|
1
|
3895
|
my($invocant) = shift; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# Called as object method |
110
|
2215
|
50
|
|
|
|
4948
|
if(my $class = ref $invocant) |
111
|
|
|
|
|
|
|
{ |
112
|
2215
|
100
|
|
|
|
4544
|
if(@_) |
113
|
|
|
|
|
|
|
{ |
114
|
3
|
|
|
|
|
10
|
return $invocant->{'locale'} = shift; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
2212
|
|
|
|
|
3813
|
my $locale = $invocant->{'locale'}; |
118
|
|
|
|
|
|
|
|
119
|
2212
|
100
|
|
|
|
4577
|
unless($locale) |
120
|
|
|
|
|
|
|
{ |
121
|
2208
|
100
|
|
|
|
4690
|
if(my $parent = $invocant->parent) |
122
|
|
|
|
|
|
|
{ |
123
|
2205
|
50
|
|
|
|
5427
|
if(my $locale = $parent->locale) |
124
|
|
|
|
|
|
|
{ |
125
|
2205
|
|
|
|
|
9425
|
return $locale; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
3
|
|
|
|
|
7
|
else { return $class->default_locale } |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
4
|
|
33
|
|
|
18
|
return $locale || $class->default_locale; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
else # Called as class method |
134
|
|
|
|
|
|
|
{ |
135
|
0
|
0
|
|
|
|
|
if(@_) |
136
|
|
|
|
|
|
|
{ |
137
|
0
|
|
|
|
|
|
return $invocant->default_locale(shift); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
return $invocant->default_locale; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
1; |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
__END__ |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=encoding utf-8 |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 NAME |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Rose::HTML::Object::Message::Localized - Localized message object. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 SYNOPSIS |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
use Rose::HTML::Form::Field::Integer; |
157
|
|
|
|
|
|
|
Rose::HTML::Form::Field::Integer->load_all_messages; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
use Rose::HTML::Object::Messages qw(NUM_INVALID_INTEGER); |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
$localizer = Rose::HTML::Object->default_localizer; |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
$msg = |
164
|
|
|
|
|
|
|
Rose::HTML::Object::Message::Localized->new( |
165
|
|
|
|
|
|
|
localizer => $localizer, |
166
|
|
|
|
|
|
|
id => NUM_INVALID_INTEGER, |
167
|
|
|
|
|
|
|
args => { label => 'XYZ' }); |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
print $msg->localized_text; # XYZ must be an integer. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
$msg->locale('fr'); |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
print $msg->localized_text; # XYZ doit être un entier. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 DESCRIPTION |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
L<Rose::HTML::Object::Message::Localized> objects encapsulate a localized text message with an integer L<id|/id> and an optional set of name/value pairs to be used to fill in any placeholders in the message text. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
This class inherits from L<Rose::HTML::Object::Message>. See the L<Rose::HTML::Object::Message> documentation for more information. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 OVERLOADING |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Stringification is overloaded to call the L<localized_text|/localized_text> method. In numeric and boolean contexts, L<Rose::HTML::Object::Message::Localized> objects always evaluate to true. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 CLASS METHODS |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=over 4 |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=item B<default_locale [LOCALE]> |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Get or set the default L<locale|Rose::HTML::Object::Message::Localizer/LOCALES>. Defaults to C<en>. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=item B<default_localizer [LOCALIZER]> |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
Get or set the default L<Rose::HTML::Object::Message::Localizer>-derived localizer object. Defaults to the L<default_localizer|Rose::HTML::Object/default_localizer> of the generic object class for this HTML object class hierarchy (L<Rose::HTML::Object>, by default). |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=back |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=over 4 |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=item B<new [ PARAMS | TEXT ]> |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Constructs a new L<Rose::HTML::Object::Message::Localized> object. If a single argument is passed, it is taken as the value for the L<text|Rose::HTML::Object::Message/text> parameter. Otherwise, PARAMS name/value pairs are expected. Any object method is a valid parameter name. |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=back |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=head1 OBJECT METHODS |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=over 4 |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=item B<args [ PARAMS | HASHREF ]> |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
Get or set the name/value pairs to be used to fill in any placeholders in the localized message text. To set, pass a list of name/value pairs or a reference to a hash of name/value pairs. Values must be strings, code references, or references to arrays of strings or code references. Code references are evaluated each time a message with placeholders is constructed. |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
See the L<LOCALIZED TEXT|Rose::HTML::Object::Message::Localizer/"LOCALIZED TEXT"> section of the L<Rose::HTML::Object::Message::Localizer> documentation for more information on message text placeholders. |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=item B<id [INT]> |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
Get or set the message's integer identifier. |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=item B<locale [LOCALE]> |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Get or set the L<locale string|Rose::HTML::Object::Message::Localizer/LOCALES> for this message. If no locale is set but a L<parent|/parent> is defined and has a locale, then the L<parent|/parent>'s C<locale()> is returned. If the L<parent|/parent> doesn't exist or has no locale set, the L<default_locale|/default_locale> is returned. |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=item B<localizer [LOCALIZER]> |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
Get or set the L<Rose::HTML::Object::Message::Localizer>-derived object used to localize message text. If no localizer is set but a L<parent|/parent> is defined, then the L<parent|/parent>'s C<localizer()> is returned. Otherwise, the L<default_localizer|/default_localizer> is returned. |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=item B<localized_text> |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
Asks the L<localizer|/localizer> to produce the localized version of the message text for the current L<locale|/locale> and L<args|/args>. The localized text is returned. |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=item B<parent [OBJECT]> |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
Get or set a L<weakened|Scalar::Util/weaken> reference to a parent object. This parent must have a C<localizer()> method that returns a L<Rose::HTML::Object::Message::Localizer>-derived object and a C<locale()> method that returns a L<locale string|Rose::HTML::Object::Message::Localizer/LOCALES>. |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=back |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=head1 AUTHOR |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
John C. Siracusa (siracusa@gmail.com) |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=head1 LICENSE |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
Copyright (c) 2010 by John C. Siracusa. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |