blib/lib/CLDR/Number/Format/Percent.pm

filter: Statementstmt 100% 40 / 40 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 50.0% 1 / 2 totaltotal 98.2% 57 / 58 CC 4 SCAR 4.8
CC
4
Cov
100%
format
3.0
__ANON__
2.0
BEGIN
1.0
CRAP 1.6
« blib/lib/CLDR/Number/Role/Base.pm ↑ Summary blib/lib/CLDR/Number/Format/Decimal.pm »
1 package CLDR::Number::Format::Percent;
2  
3 8 ▶use v5.8.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use CLDR::Number::Constant qw( $P );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 8 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 8 our $VERSION = '0.17';
12  
13 8 with qw( CLDR::Number::Role::Format );
14  
15 has permil => (
16 is => 'rw',
17 11 ▶ coerce => sub { $_[0] ? 1 : 0 },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 2 9 11
18 8 default => 0,
19 );
20  
21 8 has percent_sign => (
22 is => 'rw',
23 );
24  
25 8 has permil_sign => (
26 is => 'rw',
27 );
28  
29 8 has _pattern_type => (
30 is => 'ro',
31 default => 'percent',
32 );
33  
34 after _trigger_locale => sub {
35 12 ▶ my ($self) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
36  
37 12 $self->_build_signs(qw{ percent_sign permil_sign });
38 8 };
39  
40 ▶sub BUILD {}
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
41  
42 sub format {
43 18 ▶ my ($self, $num) = @_;
Subroutine format: called CC=3 SCAR=11.0
Pod documented
44 18 my ($factor, $sign);
45  
46 18 $num = $self->_validate_number(format => $num);
47 18 ▶ return undef unless defined $num;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $num 1 17 18
48  
49 17 ▶ if ($self->permil) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->permil) { } 3 14 17
50 3 $factor = 1_000;
51 3 $sign = $self->permil_sign;
52 }
53 else {
54 14 $factor = 100;
55 14 $sign = $self->percent_sign;
56 }
57  
58 17 my $format = $self->_format_number($num * $factor);
59 17 $format =~ s{$P}{$sign};
60  
61 17 return $format;
62 }
63  
64 8 1;
65  
66 __END__
« blib/lib/CLDR/Number/Role/Base.pm ↑ Summary blib/lib/CLDR/Number/Format/Decimal.pm »