File Coverage

blib/lib/Mojolicious/Plugin/Number/Commify.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition 2 2 100.0
subroutine 3 3 100.0
pod 1 1 100.0
total 15 15 100.0


line stmt bran cond sub pod time code
1             package Mojolicious::Plugin::Number::Commify;
2 2     2   517573 use Mojo::Base 'Mojolicious::Plugin';
  2         5  
  2         15  
3              
4             our $VERSION = 0.022;
5              
6             sub register {
7 2     2 1 25460 my ($self, $app, $cfg) = @_;
8             $app->helper(commify => sub {
9 7     7   1723 my ($self, $number) = @_;
10 7   100     37 my $sep = $cfg->{separator} // ',';
11 7         60 $number =~ s/(
12             ^[-+]? # beginning of number.
13             \d+? # first digits before first comma
14             (?= # followed by, (but not included in the match) :
15             (?>(?:\d{3})+) # some positive multiple of three digits.
16             (?!\d) # an *exact* multiple, not x * 3 + 1 or whatever.
17             )
18             | # or:
19             \G\d{3} # after the last group, get three digits
20             (?=\d) # but they have to have more digits after them.
21             )/$1$sep/xg;
22 7         46 $number;
23 2         16 });
24             }
25              
26             1;
27             __END__