line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Locale::File::PO::Header; ## no critic (TidyCode) |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
766722
|
use Moose; |
|
5
|
|
|
|
|
1900429
|
|
|
5
|
|
|
|
|
34
|
|
4
|
5
|
|
|
5
|
|
40156
|
use MooseX::StrictConstructor; |
|
5
|
|
|
|
|
132592
|
|
|
5
|
|
|
|
|
18
|
|
5
|
5
|
|
|
5
|
|
44788
|
use namespace::autoclean; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
28
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Locale::File::PO::Header::Item; |
8
|
|
|
|
|
|
|
require Locale::File::PO::Header::MailItem; |
9
|
|
|
|
|
|
|
require Locale::File::PO::Header::ContentTypeItem; |
10
|
|
|
|
|
|
|
require Locale::File::PO::Header::ExtendedItem; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.004'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has _header => ( |
15
|
|
|
|
|
|
|
is => 'rw', |
16
|
|
|
|
|
|
|
init_arg => undef, |
17
|
|
|
|
|
|
|
lazy => 1, |
18
|
|
|
|
|
|
|
default => \&_default_header, |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has _header_index => ( |
22
|
|
|
|
|
|
|
is => 'ro', |
23
|
|
|
|
|
|
|
init_arg => undef, |
24
|
|
|
|
|
|
|
lazy => 1, |
25
|
|
|
|
|
|
|
default => sub { |
26
|
|
|
|
|
|
|
my $self = shift; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my %header_index; |
29
|
|
|
|
|
|
|
my $index = 0; |
30
|
|
|
|
|
|
|
for my $item ( @{ $self->_header } ) { |
31
|
|
|
|
|
|
|
for my $key ( $item->header_keys ) { |
32
|
|
|
|
|
|
|
$header_index{$key} = $index; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
$index++; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
return \%header_index; |
38
|
|
|
|
|
|
|
}, |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub _default_header { |
42
|
3
|
|
|
3
|
|
7
|
my $self = shift; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
return [ |
45
|
3
|
|
|
|
|
92
|
Locale::File::PO::Header::Item->new( |
46
|
|
|
|
|
|
|
name => 'Project-Id-Version', |
47
|
|
|
|
|
|
|
), |
48
|
|
|
|
|
|
|
Locale::File::PO::Header::MailItem->new( |
49
|
|
|
|
|
|
|
name => 'Report-Msgid-Bugs-To', |
50
|
|
|
|
|
|
|
), |
51
|
|
|
|
|
|
|
Locale::File::PO::Header::Item->new( |
52
|
|
|
|
|
|
|
name => 'POT-Creation-Date', |
53
|
|
|
|
|
|
|
), |
54
|
|
|
|
|
|
|
Locale::File::PO::Header::Item->new( |
55
|
|
|
|
|
|
|
name => 'PO-Revision-Date', |
56
|
|
|
|
|
|
|
), |
57
|
|
|
|
|
|
|
Locale::File::PO::Header::MailItem->new( |
58
|
|
|
|
|
|
|
name => 'Last-Translator', |
59
|
|
|
|
|
|
|
), |
60
|
|
|
|
|
|
|
Locale::File::PO::Header::MailItem->new( |
61
|
|
|
|
|
|
|
name => 'Language-Team', |
62
|
|
|
|
|
|
|
), |
63
|
|
|
|
|
|
|
Locale::File::PO::Header::Item->new( |
64
|
|
|
|
|
|
|
name => 'MIME-Version', |
65
|
|
|
|
|
|
|
default => '1.0', |
66
|
|
|
|
|
|
|
), |
67
|
|
|
|
|
|
|
Locale::File::PO::Header::ContentTypeItem->new( |
68
|
|
|
|
|
|
|
name => 'Content-Type', |
69
|
|
|
|
|
|
|
default => { |
70
|
|
|
|
|
|
|
'Content-Type' => 'text/plain', |
71
|
|
|
|
|
|
|
charset => 'ISO-8859-1', |
72
|
|
|
|
|
|
|
}, |
73
|
|
|
|
|
|
|
), |
74
|
|
|
|
|
|
|
Locale::File::PO::Header::Item->new( |
75
|
|
|
|
|
|
|
name => 'Content-Transfer-Encoding', |
76
|
|
|
|
|
|
|
default => '8bit', |
77
|
|
|
|
|
|
|
), |
78
|
|
|
|
|
|
|
Locale::File::PO::Header::Item->new( |
79
|
|
|
|
|
|
|
name => 'Plural-Forms', |
80
|
|
|
|
|
|
|
), |
81
|
|
|
|
|
|
|
Locale::File::PO::Header::ExtendedItem->new( |
82
|
|
|
|
|
|
|
name => 'extended', |
83
|
|
|
|
|
|
|
), |
84
|
|
|
|
|
|
|
]; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# get only |
88
|
|
|
|
|
|
|
sub all_keys { |
89
|
1
|
|
|
1
|
1
|
6
|
my $self = shift; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
return map { |
92
|
11
|
|
|
|
|
33
|
$_->header_keys; |
93
|
1
|
|
|
|
|
1
|
} @{ $self->_header }; |
|
1
|
|
|
|
|
29
|
|
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# set only |
97
|
|
|
|
|
|
|
sub data { |
98
|
1
|
|
|
1
|
1
|
3
|
my ($self, $data) = @_; |
99
|
|
|
|
|
|
|
|
100
|
1
|
50
|
|
|
|
4
|
ref $data eq 'HASH' |
101
|
|
|
|
|
|
|
or confess 'Hash reference expected'; |
102
|
1
|
|
|
|
|
3
|
$self->_header( $self->_default_header ); |
103
|
1
|
|
|
|
|
2
|
for my $key ( keys %{$data} ) { |
|
1
|
|
|
|
|
5
|
|
104
|
15
|
|
|
|
|
28
|
my $value = delete $data->{$key}; |
105
|
15
|
50
|
33
|
|
|
47
|
if ( defined $value && length $value ) { |
106
|
15
|
|
|
|
|
373
|
my $index = $self->_header_index->{$key}; |
107
|
15
|
50
|
|
|
|
23
|
defined $index |
108
|
|
|
|
|
|
|
or confess "Unknown key $key"; |
109
|
15
|
|
|
|
|
327
|
my $item = $self->_header->[$index]->data($key, $value); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
1
|
|
|
|
|
4
|
return; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub item { |
117
|
5
|
|
|
5
|
1
|
13
|
my ($self, $key, $value) = @_; |
118
|
|
|
|
|
|
|
|
119
|
5
|
50
|
|
|
|
11
|
defined $key |
120
|
|
|
|
|
|
|
or confess 'Undefined key'; |
121
|
5
|
|
|
|
|
127
|
my $index = $self->_header_index->{$key}; |
122
|
5
|
50
|
|
|
|
10
|
defined $index |
123
|
|
|
|
|
|
|
or confess "Unknown key $key"; |
124
|
5
|
|
|
|
|
111
|
my $item = $self->_header->[$index]; |
125
|
|
|
|
|
|
|
# set |
126
|
5
|
50
|
33
|
|
|
13
|
if ( defined $value && length $value ) { |
127
|
0
|
|
|
|
|
0
|
return $item->data($key, $value); |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# get |
131
|
5
|
|
|
|
|
15
|
return $item->data($key); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# get only |
135
|
|
|
|
|
|
|
sub items { |
136
|
1
|
|
|
1
|
1
|
5
|
my ($self, @args) = @_; |
137
|
|
|
|
|
|
|
|
138
|
1
|
|
|
|
|
3
|
return map { $self->item($_) } @args; |
|
4
|
|
|
|
|
21
|
|
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub msgstr { |
142
|
5
|
|
|
5
|
1
|
19
|
my ($self, @args) = @_; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
# set |
145
|
5
|
100
|
|
|
|
14
|
if (@args) { |
146
|
2
|
50
|
|
|
|
8
|
my $msgstr = defined $args[0] ? $args[0] : q{}; |
147
|
2
|
|
|
|
|
4
|
for my $item ( @{ $self->_header } ) { |
|
2
|
|
|
|
|
61
|
|
148
|
22
|
|
|
|
|
74
|
$item->extract_msgstr(\$msgstr); |
149
|
|
|
|
|
|
|
} |
150
|
2
|
|
|
|
|
9
|
return; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
# get |
154
|
3
|
|
|
|
|
5
|
return join "\n", map { $_->lines } @{ $self->_header }; |
|
33
|
|
|
|
|
81
|
|
|
3
|
|
|
|
|
81
|
|
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
# $Id:$ |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
1; |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
__END__ |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 NAME |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Locale::File::PO::Header - Utils to build/extract the PO header |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
$Id: Utils.pm 602 2011-11-13 13:49:23Z steffenw $ |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
$HeadURL: https://dbd-po.svn.sourceforge.net/svnroot/dbd-po/Locale-File-PO-Header/trunk/lib/Locale/PO/Utils.pm $ |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 VERSION |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
0.004 |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 SYNOPSIS |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
require Locale::PO::Utils; |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
$obj = Locale::PO::Utils->new; |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 DESCRIPTION |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Utils to build or extract the PO header |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
The header of a PO file is quite complex. |
188
|
|
|
|
|
|
|
This module helps to build the header and extract. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head2 method msgstr - read and write the header as string |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head3 reader |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
$msgstr = $obj->msgstr; |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
If nothing was set before it returns a minimal header: |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
MIME-Version: 1.0 |
201
|
|
|
|
|
|
|
Content-Type: text/plain; charset=ISO-8859-1 |
202
|
|
|
|
|
|
|
Content-Transfer-Encoding: 8bit |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head3 writer |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
$obj->msgstr(<<'EOT'); |
207
|
|
|
|
|
|
|
Content-Type: text/plain; charset=UTF-8 |
208
|
|
|
|
|
|
|
EOT |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
If nothing else was set before the msgstr is: |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
MIME-Version: 1.0 |
213
|
|
|
|
|
|
|
Content-Type: text/plain; charset=UTF-8 |
214
|
|
|
|
|
|
|
Content-Transfer-Encoding: 8bit |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head2 method all_keys - names of all items |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
This sub returns all header keys you can set or get. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
@all_keys = $obj->all_keys; |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
The returned array is: |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
qw( |
225
|
|
|
|
|
|
|
Project-Id-Version |
226
|
|
|
|
|
|
|
Report-Msgid-Bugs-To_name |
227
|
|
|
|
|
|
|
Report-Msgid-Bugs-To_address |
228
|
|
|
|
|
|
|
POT-Creation-Date |
229
|
|
|
|
|
|
|
PO-Revision-Date |
230
|
|
|
|
|
|
|
Last-Translator_name |
231
|
|
|
|
|
|
|
Last-Translator_address |
232
|
|
|
|
|
|
|
Language-Team_name |
233
|
|
|
|
|
|
|
Language-Team_address |
234
|
|
|
|
|
|
|
MIME-Version |
235
|
|
|
|
|
|
|
Content-Type |
236
|
|
|
|
|
|
|
charset |
237
|
|
|
|
|
|
|
Content-Transfer-Encoding |
238
|
|
|
|
|
|
|
Plural-Forms |
239
|
|
|
|
|
|
|
extended |
240
|
|
|
|
|
|
|
) |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=head2 method data - modify lots of items |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
$obj->data({ |
245
|
|
|
|
|
|
|
Project-Id-Version => 'Example', |
246
|
|
|
|
|
|
|
Report-Msgid-Bugs-To_address => 'bug@example.com', |
247
|
|
|
|
|
|
|
extended => { |
248
|
|
|
|
|
|
|
X-Example => 'This is an example', |
249
|
|
|
|
|
|
|
}, |
250
|
|
|
|
|
|
|
}); |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
If nothing else was set before the msgstr is: |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
Project-Id-Version: Example |
255
|
|
|
|
|
|
|
Report-Msgid-Bugs-To: bug@example.com |
256
|
|
|
|
|
|
|
MIME-Version: 1.0 |
257
|
|
|
|
|
|
|
Content-Type: text/plain; charset=ISO-8859-1 |
258
|
|
|
|
|
|
|
Content-Transfer-Encoding: 8bit |
259
|
|
|
|
|
|
|
X-Example: This is an example |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
An example to write all keys: |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
$obj->data({ |
264
|
|
|
|
|
|
|
'Project-Id-Version' => 'Testproject', |
265
|
|
|
|
|
|
|
'Report-Msgid-Bugs-To_name' => 'Bug Reporter', |
266
|
|
|
|
|
|
|
'Report-Msgid-Bugs-To_address' => 'bug@example.org', |
267
|
|
|
|
|
|
|
'POT-Creation-Date' => 'no POT creation date', |
268
|
|
|
|
|
|
|
'PO-Revision-Date' => 'no PO revision date', |
269
|
|
|
|
|
|
|
'Last-Translator_name' => 'Steffen Winkler', |
270
|
|
|
|
|
|
|
'Last-Translator_address' => 'steffenw@example.org', |
271
|
|
|
|
|
|
|
'Language-Team_name' => 'MyTeam', |
272
|
|
|
|
|
|
|
'Language-Team_address' => 'cpan@example.org', |
273
|
|
|
|
|
|
|
'MIME-Version' => '1.0', |
274
|
|
|
|
|
|
|
'Content-Type' => 'text/plain', |
275
|
|
|
|
|
|
|
'charset' => 'utf-8', |
276
|
|
|
|
|
|
|
'Content-Transfer-Encoding' => '8bit', |
277
|
|
|
|
|
|
|
'extended' => [ |
278
|
|
|
|
|
|
|
'X-Poedit-Language' => 'German', |
279
|
|
|
|
|
|
|
'X-Poedit-Country' => 'GERMANY', |
280
|
|
|
|
|
|
|
'X-Poedit-SourceCharset' => 'utf-8', |
281
|
|
|
|
|
|
|
], |
282
|
|
|
|
|
|
|
}); |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
The msgstr is: |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
Project-Id-Version: Testproject |
287
|
|
|
|
|
|
|
Report-Msgid-Bugs-To: Bug Reporter <bug@example.org> |
288
|
|
|
|
|
|
|
POT-Creation-Date: no POT creation date |
289
|
|
|
|
|
|
|
PO-Revision-Date: no PO revision date |
290
|
|
|
|
|
|
|
Last-Translator: Steffen Winkler <steffenw@example.org> |
291
|
|
|
|
|
|
|
Language-Team: MyTeam <cpan@example.org> |
292
|
|
|
|
|
|
|
MIME-Version: 1.0 |
293
|
|
|
|
|
|
|
Content-Type: text/plain; charset=utf-8 |
294
|
|
|
|
|
|
|
Content-Transfer-Encoding: 8bit |
295
|
|
|
|
|
|
|
X-Poedit-Language: German |
296
|
|
|
|
|
|
|
X-Poedit-Country: GERMANY |
297
|
|
|
|
|
|
|
X-Poedit-SourceCharset: utf-8 |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
=head2 method item - read or write one item |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
=head3 writer |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
$obj->item( 'Project-Id-Version' => 'Example' ); |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
=head3 reader |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
$value = $obj->item('Project-Id-Version'); |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
=head2 method items - read lots of items |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
@values = $obj->items( @keys ); |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
@values = $obj->items( qw(Project-Id-Version charset) ); |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
=head1 EXAMPLE |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
Inside of this distribution is a directory named example. |
318
|
|
|
|
|
|
|
Run the *.pl files. |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
=head1 DIAGNOSTICS |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
none |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
=head1 CONFIGURATION AND ENVIRONMENT |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
none |
327
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
329
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
L<Moose|Moose> |
331
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
L<MooseX::StrictConstructor|MooseX::StrictConstructor> |
333
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
L<namespace::autoclean|namespace::autoclean>; |
335
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
L<syntax|syntax> |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
L<Clone|Clone> |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
=head1 INCOMPATIBILITIES |
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
not known |
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
345
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
not known |
347
|
|
|
|
|
|
|
|
348
|
|
|
|
|
|
|
=head1 SEE ALSO |
349
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
L<http://en.wikipedia.org/wiki/Gettext> |
351
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
=head1 AUTHOR |
353
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
Steffen Winkler |
355
|
|
|
|
|
|
|
|
356
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
357
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
Copyright (c) 2011 - 2017, |
359
|
|
|
|
|
|
|
Steffen Winkler |
360
|
|
|
|
|
|
|
C<< <steffenw at cpan.org> >>. |
361
|
|
|
|
|
|
|
All rights reserved. |
362
|
|
|
|
|
|
|
|
363
|
|
|
|
|
|
|
This module is free software; |
364
|
|
|
|
|
|
|
you can redistribute it and/or modify it |
365
|
|
|
|
|
|
|
under the same terms as Perl itself. |