line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DTL::Fast::Filter::Filesizeformat; |
2
|
2
|
|
|
2
|
|
1215
|
use strict; use utf8; use warnings FATAL => 'all'; |
|
2
|
|
|
2
|
|
4
|
|
|
2
|
|
|
2
|
|
48
|
|
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
53
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
70
|
|
3
|
2
|
|
|
2
|
|
9
|
use parent 'DTL::Fast::Filter'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
10
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
$DTL::Fast::FILTER_HANDLERS{'filesizeformat'} = __PACKAGE__; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
129
|
use Scalar::Util qw(looks_like_number); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
711
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @SUFFIX = ( |
10
|
|
|
|
|
|
|
['KB', 1024] |
11
|
|
|
|
|
|
|
); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
unshift @SUFFIX, ['MB', $SUFFIX[0]->[1] * 1024]; |
14
|
|
|
|
|
|
|
unshift @SUFFIX, ['GB', $SUFFIX[0]->[1] * 1024]; |
15
|
|
|
|
|
|
|
unshift @SUFFIX, ['TB', $SUFFIX[0]->[1] * 1024]; |
16
|
|
|
|
|
|
|
unshift @SUFFIX, ['PB', $SUFFIX[0]->[1] * 1024]; |
17
|
|
|
|
|
|
|
unshift @SUFFIX, ['EB', $SUFFIX[0]->[1] * 1024]; |
18
|
|
|
|
|
|
|
unshift @SUFFIX, ['ZB', $SUFFIX[0]->[1] * 1024]; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
#@Override |
21
|
|
|
|
|
|
|
sub filter |
22
|
|
|
|
|
|
|
{ |
23
|
8
|
|
|
8
|
0
|
11
|
shift; # self |
24
|
8
|
|
|
|
|
10
|
shift; # filter_manager |
25
|
8
|
|
|
|
|
9
|
my $value = shift; # value |
26
|
8
|
|
|
|
|
9
|
shift; # context |
27
|
|
|
|
|
|
|
|
28
|
8
|
50
|
|
|
|
24
|
if( looks_like_number($value) ) |
29
|
|
|
|
|
|
|
{ |
30
|
8
|
|
|
|
|
10
|
my $str_suffix = 'B'; |
31
|
|
|
|
|
|
|
|
32
|
8
|
|
|
|
|
12
|
foreach my $suffix (@SUFFIX) |
33
|
|
|
|
|
|
|
{ |
34
|
35
|
100
|
|
|
|
83
|
if( $value > $suffix->[1] ) |
35
|
|
|
|
|
|
|
{ |
36
|
7
|
|
|
|
|
10
|
$str_suffix = $suffix->[0]; |
37
|
7
|
|
|
|
|
49
|
$value = sprintf '%.01f', $value / $suffix->[1]; |
38
|
7
|
|
|
|
|
11
|
last; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
8
|
|
|
|
|
23
|
$value = sprintf '%s %s', $value, $str_suffix; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
8
|
|
|
|
|
28
|
return $value; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
1; |