line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::MessageFormat; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
57553
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
117
|
|
4
|
2
|
|
|
2
|
|
12
|
use vars qw($VERSION); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
277
|
|
5
|
|
|
|
|
|
|
$VERSION = 0.01; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
2885
|
use Text::Balanced qw(extract_multiple extract_bracketed extract_delimited); |
|
2
|
|
|
|
|
52947
|
|
|
2
|
|
|
|
|
1225
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
25
|
|
|
25
|
0
|
32944
|
my($class, $format) = @_; |
11
|
25
|
|
|
|
|
80
|
my $formats = $class->_parse_format($format); |
12
|
25
|
|
|
|
|
108
|
bless { _formats => $formats }, $class; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub format { |
16
|
25
|
|
|
25
|
0
|
128
|
my($self, @args) = @_; |
17
|
25
|
|
|
|
|
41
|
return join '', map $_->format(\@args), @{$self->{_formats}}; |
|
25
|
|
|
|
|
106
|
|
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub _parse_format { |
21
|
25
|
|
|
25
|
|
42
|
my($class, $format) = @_; |
22
|
|
|
|
|
|
|
my @blocks = map { |
23
|
45
|
100
|
|
|
|
3426
|
if (UNIVERSAL::isa($_, 'FormatElement')) { |
|
|
100
|
|
|
|
|
|
24
|
24
|
|
|
|
|
73
|
$class->_handle_format_element($$_); |
25
|
|
|
|
|
|
|
} elsif (UNIVERSAL::isa($_, 'QuotedString')) { |
26
|
7
|
|
|
|
|
19
|
$class->_handle_quoted_string($$_); |
27
|
|
|
|
|
|
|
} else { |
28
|
14
|
|
|
|
|
40
|
$class->_handle_literal($_); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} extract_multiple( |
31
|
|
|
|
|
|
|
$format, [ |
32
|
85
|
|
|
85
|
|
5325
|
{ FormatElement => sub { extract_bracketed($_[0], q({})); } }, |
33
|
61
|
|
|
61
|
|
3547
|
{ QuotedString => sub { extract_delimited($_[0], q(')); } }, |
34
|
25
|
|
|
|
|
257
|
], |
35
|
|
|
|
|
|
|
); |
36
|
25
|
|
|
|
|
223
|
return \@blocks; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub _handle_format_element { |
40
|
24
|
|
|
24
|
|
44
|
my($class, $pattern) = @_; |
41
|
24
|
|
|
|
|
200
|
my($index, $type, $style) = split /,\s*/, ($pattern =~ /^{(.*)}$/)[0], 3; |
42
|
|
|
|
|
|
|
|
43
|
24
|
|
|
|
|
46
|
my $element_class = 'Text::MessageFormat::Element'; |
44
|
24
|
100
|
|
|
|
80
|
$element_class .= '::' . ucfirst $type if $type; |
45
|
24
|
|
|
|
|
192
|
return bless { |
46
|
|
|
|
|
|
|
index => $index, |
47
|
|
|
|
|
|
|
type => $type, |
48
|
|
|
|
|
|
|
style => $style, |
49
|
|
|
|
|
|
|
}, $element_class; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
sub _handle_quoted_string { |
52
|
7
|
|
|
7
|
|
11
|
my($class, $pattern) = @_; |
53
|
7
|
|
|
|
|
32
|
$pattern =~ s/^'(.*)'$/$1/; |
54
|
7
|
100
|
|
|
|
16
|
my $literal = $pattern eq '' ? q(') : $pattern; |
55
|
7
|
|
|
|
|
31
|
return bless { |
56
|
|
|
|
|
|
|
literal => $literal, |
57
|
|
|
|
|
|
|
}, 'Text::MessageFormat::String'; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _handle_literal { |
61
|
14
|
|
|
14
|
|
23
|
my($class, $pattern) = @_; |
62
|
14
|
|
|
|
|
71
|
return bless { |
63
|
|
|
|
|
|
|
literal => $pattern, |
64
|
|
|
|
|
|
|
}, 'Text::MessageFormat::String'; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
package Text::MessageFormat::String; |
68
|
21
|
|
|
21
|
|
102
|
sub format { shift->{literal} } |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
package Text::MessageFormat::Element; |
71
|
|
|
|
|
|
|
sub format { |
72
|
24
|
|
|
24
|
|
36
|
my($self, $args) = @_; |
73
|
24
|
|
|
|
|
172
|
return $args->[$self->{index}]; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
package Text::MessageFormat::Element::Number; |
77
|
2
|
|
|
2
|
|
19
|
use base qw(Text::MessageFormat::Element); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
1342
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
package Text::MessageFormat::Element::Date; |
80
|
2
|
|
|
2
|
|
13
|
use base qw(Text::MessageFormat::Element); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1014
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
package Text::MessageFormat::Element::Time; |
83
|
2
|
|
|
2
|
|
13
|
use base qw(Text::MessageFormat::Element); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
998
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
package Text::MessageFormat::Element::Choice; |
86
|
2
|
|
|
2
|
|
12
|
use base qw(Text::MessageFormat::Element); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
979
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |
89
|
|
|
|
|
|
|
__END__ |