line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CLDR::Number::Format::Percent; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
82
|
use v5.8.1; |
|
8
|
|
|
|
|
18
|
|
4
|
8
|
|
|
8
|
|
32
|
use utf8; |
|
8
|
|
|
|
|
9
|
|
|
8
|
|
|
|
|
47
|
|
5
|
8
|
|
|
8
|
|
164
|
use Carp; |
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
588
|
|
6
|
8
|
|
|
8
|
|
34
|
use CLDR::Number::Constant qw( $P ); |
|
8
|
|
|
|
|
9
|
|
|
8
|
|
|
|
|
757
|
|
7
|
|
|
|
|
|
|
|
8
|
8
|
|
|
8
|
|
33
|
use Moo; |
|
8
|
|
|
|
|
8
|
|
|
8
|
|
|
|
|
54
|
|
9
|
8
|
|
|
8
|
|
2080
|
use namespace::clean; |
|
8
|
|
|
|
|
12
|
|
|
8
|
|
|
|
|
56
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.19'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
with qw( CLDR::Number::Role::Format ); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has permil => ( |
16
|
|
|
|
|
|
|
is => 'rw', |
17
|
|
|
|
|
|
|
coerce => sub { $_[0] ? 1 : 0 }, |
18
|
|
|
|
|
|
|
default => 0, |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has percent_sign => ( |
22
|
|
|
|
|
|
|
is => 'rw', |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has permil_sign => ( |
26
|
|
|
|
|
|
|
is => 'rw', |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has _pattern_type => ( |
30
|
|
|
|
|
|
|
is => 'ro', |
31
|
|
|
|
|
|
|
default => 'percent', |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
after _trigger_locale => sub { |
35
|
|
|
|
|
|
|
my ($self) = @_; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
$self->_build_signs(qw{ percent_sign permil_sign }); |
38
|
|
|
|
|
|
|
}; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub BUILD {} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub format { |
43
|
18
|
|
|
18
|
1
|
535
|
my ($self, $num) = @_; |
44
|
18
|
|
|
|
|
108
|
my ($factor, $sign); |
45
|
|
|
|
|
|
|
|
46
|
18
|
|
|
|
|
50
|
$num = $self->_validate_number(format => $num); |
47
|
18
|
100
|
|
|
|
47
|
return undef unless defined $num; |
48
|
|
|
|
|
|
|
|
49
|
17
|
100
|
|
|
|
201
|
if ($self->permil) { |
50
|
3
|
|
|
|
|
1166
|
$factor = 1_000; |
51
|
3
|
|
|
|
|
10
|
$sign = $self->permil_sign; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else { |
54
|
14
|
|
|
|
|
2389
|
$factor = 100; |
55
|
14
|
|
|
|
|
37
|
$sign = $self->percent_sign; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
17
|
|
|
|
|
62
|
my $format = $self->_format_number($num * $factor); |
59
|
17
|
|
|
|
|
110
|
$format =~ s{$P}{$sign}; |
60
|
|
|
|
|
|
|
|
61
|
17
|
|
|
|
|
64
|
return $format; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
__END__ |