Quantity/Number/Bytes.pm

filter: Statementstmt 92.5% 25 / 27 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 2 totaltotal 86.8% 33 / 38 CC 3 SCAR 5.8
CC
3
Cov
93%
readable_value
3.0
scale
2.0
BEGIN
1.0
CRAP 1.8
« Quantity/Abstract/Compound.pm ↑ Summary Quantity/Number/Integer.pm »
1 ### Change History
2 # 1998-12-02 Created. -Simon
3  
4 package Data::Quantity::Number::Bytes;
5  
6 1 require 5;
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 $VERSION = 0.001;
12  
13 1 ▶use Data::Quantity::Number::Integer '-isasubclass';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # undef = Data::Quantity::Number::Number->scale();
16 0 ▶sub scale {
Subroutine scale: not called CC=1 SCAR=6.9
Pod undocumented
17 0 return 'Bytes';
18 }
19  
20 # @ByteScales - text labels for powers of two-to-the-tenth bytes
21 1 ▶use vars qw( @ByteScales );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 @ByteScales = qw( B KB MB GB TB );
23  
24 # $value = Data::Quantity::Number::Bytes->readable_value($number)
25 # Show no more than one decimal place, followed by scale label
26 3 ▶sub readable_value {
Subroutine readable_value: called CC=3 SCAR=11.0
Pod undocumented
27 3 my $class_or_item = shift;
28 3 my $value = my $number = shift;
29
30 3 my $scale;
31 3 foreach $scale (@ByteScales) {
32 5 ▶ return ( (int($value * 10 + 0.5)/10) . $scale ) if ($value < 1024);
Branch: 1 branch
BranchTrueFalseTotal
if $value < 1024 3 2 5
33 2 $value = $value / 1024;
34 }
35 0 carp "Quantity out of range: $number Bytes";
36 }
37  
38 1 1;
« Quantity/Abstract/Compound.pm ↑ Summary Quantity/Number/Integer.pm »