line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Number::Commify; |
2
|
2
|
|
|
2
|
|
350017
|
use Mojolicious::Plugin -base; |
|
2
|
|
|
|
|
571
|
|
|
2
|
|
|
|
|
20
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = 0.041; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub register { |
7
|
2
|
|
|
2
|
1
|
11656
|
my ($self, $app, $cfg) = @_; |
8
|
|
|
|
|
|
|
$app->helper(commify => sub { |
9
|
11
|
|
|
11
|
|
732
|
my ($self, $number) = @_; |
10
|
11
|
|
100
|
|
|
34
|
my $sep = $cfg->{separator} // ','; |
11
|
11
|
|
|
|
|
90
|
$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/xgo; |
22
|
11
|
|
|
|
|
52
|
$number; |
23
|
2
|
|
|
|
|
11
|
}); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
1; |
27
|
|
|
|
|
|
|
__END__ |