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