| 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
| |||||||||||
| 33 | 2 | $value = $value / 1024; | |||||||||
| 34 | } | ||||||||||
| 35 | 0 | carp "Quantity out of range: $number Bytes"; | |||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | 1 | 1; | |||||||||