lib/HTML/FormFu/Deflator/FormatNumber.pm

filter: Statementstmt 96.5% 28 / 29 Branchbran 25.0% 1 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 87.5% 35 / 40 CC 3 SCAR 6.3
CC
3
Cov
88%
deflator
3.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.9
« lib/HTML/FormFu/Constraint/DateTime.pm ↑ Summary lib/HTML/FormFu/Element/Textarea.pm »
1 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Deflator::FormatNumber;
4 5 $HTML::FormFu::Deflator::FormatNumber::VERSION = '2.09';
5 # ABSTRACT: Format a number for a locale
6  
7 5 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use MooseX::Attribute::Chained;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 extends 'HTML::FormFu::Deflator';
10  
11 5 ▶use Number::Format;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use POSIX qw( setlocale LC_NUMERIC );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 5 has precision => (
15 is => 'rw',
16 default => 2,
17 lazy => 1,
18 isa => 'Int',
19 traits => ['Chained'],
20 );
21  
22 5 has trailing_zeroes => (
23 is => 'rw',
24 default => 0,
25 lazy => 1,
26 isa => 'Int',
27 traits => ['Chained'],
28 );
29  
30 2 ▶sub deflator {
Subroutine deflator: called CC=3 SCAR=12.0
Pod undocumented
31 2 my ( $self, $value ) = @_;
32  
33 2 my $backup_locale = setlocale(LC_NUMERIC);
34  
35 2 ▶ if ( my $locale = $self->locale ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $locale = $self->locale) 0 2 2
36  
37 # throwing errors from deflator() isn't supported
38 # if unable to set locale, return the original value
39  
40 0 ▶ setlocale( LC_NUMERIC, $locale )
Branch: 1 branch
BranchTrueFalseTotal
setlocale(1, $locale) or return $value 0 0 0
41 or return $value;
42 }
43  
44 2 my $format = Number::Format->new;
45  
46 2 $value = $format->format_number( $value, $self->precision,
47 $self->trailing_zeroes );
48  
49 # restore locale
50 2 setlocale( LC_NUMERIC, $backup_locale );
51  
52 2 return $value;
53 }
54  
55 5 __PACKAGE__->meta->make_immutable;
56  
57 5 1;
58  
59 __END__
« lib/HTML/FormFu/Constraint/DateTime.pm ↑ Summary lib/HTML/FormFu/Element/Textarea.pm »