| 1 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | |||||||||||
| 3 | package HTML::FormFu::Filter::FormatNumber; | ||||||||||
| 4 | 5 | $HTML::FormFu::Filter::FormatNumber::VERSION = '2.09'; | |||||||||
| 5 | # ABSTRACT: Convert a formatted number from a known locale | ||||||||||
| 6 | |||||||||||
| 7 | 5 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 5 | extends 'HTML::FormFu::Filter'; | |||||||||
| 9 | |||||||||||
| 10 | 5 | ▶ | use Number::Format; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 5 | ▶ | use POSIX qw( setlocale LC_NUMERIC ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 5 | __PACKAGE__->mk_inherited_accessors(qw( locale )); | |||||||||
| 14 | |||||||||||
| 15 | 1 | ▶ | sub filter { | ||||||||
|
Subroutine
filter: called CC=3 SCAR=12.0
Pod
undocumented
| |||||||||||
| 16 | 1 | my ( $self, $value ) = @_; | |||||||||
| 17 | |||||||||||
| 18 | 1 | my $backup_locale = setlocale(LC_NUMERIC); | |||||||||
| 19 | |||||||||||
| 20 | 1 | ▶ | if ( my $locale = $self->locale ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 21 | |||||||||||
| 22 | # if unable to set locale, this isn't a validation error that the user | ||||||||||
| 23 | # should see, so return the original value, rather than throwing an error | ||||||||||
| 24 | |||||||||||
| 25 | 0 | ▶ | setlocale( LC_NUMERIC, $locale ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | or return $value; | ||||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 1 | my $format = Number::Format->new; | |||||||||
| 30 | |||||||||||
| 31 | 1 | $value = $format->unformat_number($value); | |||||||||
| 32 | |||||||||||
| 33 | # restore original locale | ||||||||||
| 34 | 1 | setlocale( LC_NUMERIC, $backup_locale ); | |||||||||
| 35 | |||||||||||
| 36 | 1 | return $value; | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 5 | __PACKAGE__->meta->make_immutable; | |||||||||
| 40 | |||||||||||
| 41 | 5 | 1; | |||||||||
| 42 | |||||||||||
| 43 | __END__ | ||||||||||