File Coverage

blib/lib/Data/Quantity/Number/Bytes.pm
Criterion Covered Total %
statement 21 23 91.3
branch 2 2 100.0
condition n/a
subroutine 6 7 85.7
pod 0 2 0.0
total 29 34 85.2


line stmt bran cond sub pod time code
1             ### Change History
2             # 1998-12-02 Created. -Simon
3              
4             package Data::Quantity::Number::Bytes;
5              
6             require 5;
7 1     1   12177 use strict;
  1         2  
  1         35  
8 1     1   5 use Carp;
  1         2  
  1         62  
9              
10 1     1   5 use vars qw( $VERSION );
  1         5  
  1         53  
11             $VERSION = 0.001;
12              
13 1     1   635 use Data::Quantity::Number::Integer '-isasubclass';
  1         3  
  1         10  
14              
15             # undef = Data::Quantity::Number::Number->scale();
16             sub scale {
17 0     0 0 0 return 'Bytes';
18             }
19              
20             # @ByteScales - text labels for powers of two-to-the-tenth bytes
21 1     1   6 use vars qw( @ByteScales );
  1         1  
  1         151  
22             @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             sub readable_value {
27 3     3 0 4 my $class_or_item = shift;
28 3         7 my $value = my $number = shift;
29            
30 3         4 my $scale;
31 3         7 foreach $scale (@ByteScales) {
32 5 100       53 return ( (int($value * 10 + 0.5)/10) . $scale ) if ($value < 1024);
33 2         5 $value = $value / 1024;
34             }
35 0           carp "Quantity out of range: $number Bytes";
36             }
37              
38             1;