[freeside-commits] freeside/FS/FS/UI Web.pm, 1.26.2.2, 1.26.2.3 bytecount.pm, NONE, 1.1.2.2

Jeff Finucane,420,, jeff at wavetail.420.am
Thu Apr 19 16:38:35 PDT 2007


Update of /home/cvs/cvsroot/freeside/FS/FS/UI
In directory wavetail:/tmp/cvs-serv12212/FS/FS/UI

Modified Files:
      Tag: FREESIDE_1_7_BRANCH
	Web.pm 
Added Files:
      Tag: FREESIDE_1_7_BRANCH
	bytecount.pm 
Log Message:
break _bytecount subroutines out of FS::UI::Web (backport)

Index: Web.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/UI/Web.pm,v
retrieving revision 1.26.2.2
retrieving revision 1.26.2.3
diff -u -d -r1.26.2.2 -r1.26.2.3
--- Web.pm	19 Apr 2007 20:18:08 -0000	1.26.2.2
+++ Web.pm	19 Apr 2007 23:38:33 -0000	1.26.2.3
@@ -181,42 +181,6 @@
 
 }
 
-sub bytecount_unexact {
-  my $bc = shift;
-  return("$bc bytes")
-    if ($bc < 1000);
-  return(sprintf("%.2f Kbytes", $bc/1000))
-    if ($bc < 1000000);
-  return(sprintf("%.2f Mbytes", $bc/1000000))
-    if ($bc < 1000000000);
-  return(sprintf("%.2f Gbytes", $bc/1000000000));
-}
-
-sub parse_bytecount {
-  my $bc = shift;
-  return $bc if (($bc =~ tr/.//) > 1);
-  $bc =~ /^\s*([\d.]*)\s*([kKmMgGtT]?)[bB]?\s*$/ or return $bc;
-  my $base = $1;
-  return $bc unless length $base;
-  my $exponent = index ' kmgt', lc($2);
-  return $bc if ($exponent < 0 && $2);
-  $exponent = 0 if ($exponent < 0);
-  return $base * 1024 ** $exponent;
-}
-
-sub display_bytecount {
-  my $bc = shift;
-  return $bc unless ($bc =~ /^(\d+)$/);
-  my $conf = new FS::Conf;
-  my $f = new Number::Format;
-  my $precision = $conf->exists('datavolume-significantdigits')
-                ? $conf->config('datavolume-significantdigits')
-                : 3;
-  my $unit = $conf->exists('datavolume-forcemegabytes') ? 'M' : 'A';
-
-  return $f->format_bytes($bc, precision => $precision, unit => $unit);
-}
-
 ###
 # cust_main report subroutines
 ###

--- NEW FILE: bytecount.pm ---
package FS::UI::bytecount;

use strict;
use vars qw($DEBUG $me);
use FS::Conf;
use Number::Format;

$DEBUG = 0;
$me = '[FS::UID::bytecount]';

=head1 NAME

FS::UI::bytecount - Subroutines for parsing and displaying byte counters

=head1 SYNOPSIS

  use FS::UI::bytecount;

=head1 SUBROUTINES

=over 4

=item bytecount_unexact COUNT

Returns a two decimal place value for COUNT followed by bytes, Kbytes, Mbytes,
or GBytes as appropriate.

=cut

sub bytecount_unexact {
  my $bc = shift;
  return("$bc bytes")
    if ($bc < 1000);
  return(sprintf("%.2f Kbytes", $bc/1000))
    if ($bc < 1000000);
  return(sprintf("%.2f Mbytes", $bc/1000000))
    if ($bc < 1000000000);
  return(sprintf("%.2f Gbytes", $bc/1000000000));
}

=item parse_bytecount AMOUNT

Accepts a number (digits and a decimal point) possibly followed by k, m, g, or
t (and an optional 'b') in either case.  Returns a pure number representing
the input or the input itself if unparsable.

=cut

sub parse_bytecount {
  my $bc = shift;
  return $bc if (($bc =~ tr/.//) > 1);
  $bc =~ /^\s*([\d.]*)\s*([kKmMgGtT]?)[bB]?\s*$/ or return $bc;
  my $base = $1;
  return $bc unless length $base;
  my $exponent = index ' kmgt', lc($2);
  return $bc if ($exponent < 0 && $2);
  $exponent = 0 if ($exponent < 0);
  return $base * 1024 ** $exponent;
}

=item display_bytecount AMOUNT

Converts a pure number to a value followed possibly followed by k, m, g, or
t via Number::Format

=cut

sub display_bytecount {
  my $bc = shift;
  return $bc unless ($bc =~ /^(\d+)$/);
  my $conf = new FS::Conf;
  my $f = new Number::Format;
  my $precision = $conf->exists('datavolume-significantdigits')
                ? $conf->config('datavolume-significantdigits')
                : 3;
  my $unit = $conf->exists('datavolume-forcemegabytes') ? 'M' : 'A';

  return $f->format_bytes($bc, precision => $precision, unit => $unit);
}

=back

=head1 BUGS

Fly

=head1 SEE ALSO

L<Number::Format>

=cut

1;




More information about the freeside-commits mailing list