remove WebGUI::Utility::formatBytes
This commit is contained in:
parent
42784e1b98
commit
006a5003c2
8 changed files with 13 additions and 39 deletions
|
|
@ -17,7 +17,7 @@ package WebGUI::Asset::File;
|
||||||
use strict;
|
use strict;
|
||||||
use Carp;
|
use Carp;
|
||||||
|
|
||||||
|
use Number::Format ();
|
||||||
use Moose;
|
use Moose;
|
||||||
use WebGUI::Definition::Asset;
|
use WebGUI::Definition::Asset;
|
||||||
extends 'WebGUI::Asset';
|
extends 'WebGUI::Asset';
|
||||||
|
|
@ -573,7 +573,7 @@ sub view {
|
||||||
$var{controls} = $self->getToolbar;
|
$var{controls} = $self->getToolbar;
|
||||||
$var{fileUrl} = $self->getFileUrl;
|
$var{fileUrl} = $self->getFileUrl;
|
||||||
$var{fileIcon} = $self->getFileIconUrl;
|
$var{fileIcon} = $self->getFileIconUrl;
|
||||||
$var{fileSize} = formatBytes($self->get("assetSize"));
|
$var{fileSize} = Number::Format::format_bytes($self->get("assetSize"));
|
||||||
my $out = $self->processTemplate(\%var,undef,$self->{_viewTemplate});
|
my $out = $self->processTemplate(\%var,undef,$self->{_viewTemplate});
|
||||||
if (!$self->session->var->isAdminOn && $self->get("cacheTimeout") > 10) {
|
if (!$self->session->var->isAdminOn && $self->get("cacheTimeout") > 10) {
|
||||||
$self->session->cache->set($self->getViewCacheKey, $out, $self->get("cacheTimeout"));
|
$self->session->cache->set($self->getViewCacheKey, $out, $self->get("cacheTimeout"));
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,7 @@ has '+uiLevel' => (
|
||||||
);
|
);
|
||||||
|
|
||||||
use WebGUI::Utility;
|
use WebGUI::Utility;
|
||||||
|
use Number::Format ();
|
||||||
|
|
||||||
=head1 NAME
|
=head1 NAME
|
||||||
|
|
||||||
|
|
@ -237,7 +238,7 @@ sub view {
|
||||||
title => $child->title,
|
title => $child->title,
|
||||||
menuTitle => $child->menuTitle,
|
menuTitle => $child->menuTitle,
|
||||||
synopsis => $child->synopsis || '',
|
synopsis => $child->synopsis || '',
|
||||||
size => WebGUI::Utility::formatBytes($child->assetSize),
|
size => Number::Format::format_bytes($child->assetSize),
|
||||||
"date.epoch" => $child->revisionDate,
|
"date.epoch" => $child->revisionDate,
|
||||||
"icon.small" => $child->getIcon(1),
|
"icon.small" => $child->getIcon(1),
|
||||||
"icon.big" => $child->getIcon,
|
"icon.big" => $child->getIcon,
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ package WebGUI::Asset;
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use WebGUI::Utility qw(formatBytes);
|
use Number::Format ();
|
||||||
|
|
||||||
=head1 NAME
|
=head1 NAME
|
||||||
|
|
||||||
|
|
@ -593,7 +593,7 @@ sub www_manageClipboard {
|
||||||
."','" . $plus . "<a href=\"".$child->getUrl("op=assetManager")."\">" . $title
|
."','" . $plus . "<a href=\"".$child->getUrl("op=assetManager")."\">" . $title
|
||||||
."</a>','<p style=\"display:inline;vertical-align:middle;\"><img src=\"".$child->getIcon(1)."\" style=\"border-style:none;vertical-align:middle;\" alt=\"".$child->getName."\" /></p> ".$child->getName
|
."</a>','<p style=\"display:inline;vertical-align:middle;\"><img src=\"".$child->getIcon(1)."\" style=\"border-style:none;vertical-align:middle;\" alt=\"".$child->getName."\" /></p> ".$child->getName
|
||||||
."','".$self->session->datetime->epochToHuman($child->get("revisionDate"))
|
."','".$self->session->datetime->epochToHuman($child->get("revisionDate"))
|
||||||
."','".formatBytes($child->get("assetSize"))."');\n";
|
."','".Number::Format::format_bytes($child->get("assetSize"))."');\n";
|
||||||
$output .= "assetManager.AddLineSortData('','".$title."','".$child->getName
|
$output .= "assetManager.AddLineSortData('','".$title."','".$child->getName
|
||||||
."','".$child->get("revisionDate")."','".$child->get("assetSize")."');\n";
|
."','".$child->get("revisionDate")."','".$child->get("assetSize")."');\n";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,8 @@ package WebGUI::Asset;
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use WebGUI::Utility qw(isIn formatBytes);
|
use WebGUI::Utility qw(isIn);
|
||||||
|
use Number::Format ();
|
||||||
use JSON;
|
use JSON;
|
||||||
|
|
||||||
=head1 NAME
|
=head1 NAME
|
||||||
|
|
@ -437,7 +438,7 @@ sub www_manageTrash {
|
||||||
.'" style="vertical-align:middle;border-style:none;" alt='
|
.'" style="vertical-align:middle;border-style:none;" alt='
|
||||||
.$child->getName .'" /></p> ' . $child->getName,
|
.$child->getName .'" /></p> ' . $child->getName,
|
||||||
$self->session->datetime->epochToHuman($child->get("revisionDate")),
|
$self->session->datetime->epochToHuman($child->get("revisionDate")),
|
||||||
formatBytes($child->get("assetSize"))
|
Number::Format::format_bytes($child->get("assetSize"))
|
||||||
);
|
);
|
||||||
$amethod->('AddLineSortData',
|
$amethod->('AddLineSortData',
|
||||||
'', $title, $child->getName,
|
'', $title, $child->getName,
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ use WebGUI::Paginator;
|
||||||
use WebGUI::Utility;
|
use WebGUI::Utility;
|
||||||
use WebGUI::Macro::AdminBar;
|
use WebGUI::Macro::AdminBar;
|
||||||
use Tie::IxHash;
|
use Tie::IxHash;
|
||||||
|
use Number::Format ();
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -651,7 +652,7 @@ sub www_search {
|
||||||
revisionDate => $session->datetime->epochToHuman( $asset->get( "revisionDate" ) ),
|
revisionDate => $session->datetime->epochToHuman( $asset->get( "revisionDate" ) ),
|
||||||
hasChildren => ( $asset->hasChildren ? "+ " : " " ),
|
hasChildren => ( $asset->hasChildren ? "+ " : " " ),
|
||||||
rank => $asset->getRank,
|
rank => $asset->getRank,
|
||||||
size => formatBytes( $asset->get( 'assetSize' ) ),
|
size => Number::Format::format_bytes( $asset->get( 'assetSize' ) ),
|
||||||
);
|
);
|
||||||
|
|
||||||
# The asset icon
|
# The asset icon
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ use Net::CIDR::Lite;
|
||||||
|
|
||||||
our @ISA = qw(Exporter);
|
our @ISA = qw(Exporter);
|
||||||
our @EXPORT = qw(&isBetween &makeTabSafe &makeArrayTabSafe &randomizeHash &commify &randomizeArray &isInSubnet
|
our @EXPORT = qw(&isBetween &makeTabSafe &makeArrayTabSafe &randomizeHash &commify &randomizeArray &isInSubnet
|
||||||
&formatBytes &sortHashDescending &sortHash &isIn &makeCommaSafe &makeArrayCommaSafe &randint &round &scalarEquals
|
&sortHashDescending &sortHash &isIn &makeCommaSafe &makeArrayCommaSafe &randint &round &scalarEquals
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -39,7 +39,6 @@ This package provides miscellaneous but useful utilities to the WebGUI programme
|
||||||
|
|
||||||
use WebGUI::Utility;
|
use WebGUI::Utility;
|
||||||
$string = commify($integer);
|
$string = commify($integer);
|
||||||
$size = formatBytes($integer);
|
|
||||||
$boolean = isBetween($value, $first, $second);
|
$boolean = isBetween($value, $first, $second);
|
||||||
$boolean = isIn($value, @array);
|
$boolean = isIn($value, @array);
|
||||||
$boolean = isInSubnet($ip, \@subnets);
|
$boolean = isInSubnet($ip, \@subnets);
|
||||||
|
|
@ -92,30 +91,6 @@ sub emailRegex {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
|
||||||
|
|
||||||
=head2 formatBytes ( integer )
|
|
||||||
|
|
||||||
Returns a formatted file size like "3MB" or "44kB".
|
|
||||||
|
|
||||||
=head3 integer
|
|
||||||
|
|
||||||
An integer representing the number of bytes to format.
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
sub formatBytes {
|
|
||||||
my $size = shift;
|
|
||||||
if ($size > 1048576) {
|
|
||||||
return round($size/1048576).' MB';
|
|
||||||
} elsif ($size > 1024) {
|
|
||||||
return round($size/1024).' kB';
|
|
||||||
} else {
|
|
||||||
return $size.' B';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 isBetween ( value, first, second )
|
=head2 isBetween ( value, first, second )
|
||||||
|
|
|
||||||
|
|
@ -156,6 +156,7 @@ checkModule('IO::Socket::SSL', );
|
||||||
checkModule('Package::Stash', );
|
checkModule('Package::Stash', );
|
||||||
checkModule('HTTP::Exception', );
|
checkModule('HTTP::Exception', );
|
||||||
checkModule('Net::Twitter', "3.13006" );
|
checkModule('Net::Twitter', "3.13006" );
|
||||||
|
checkModule('Number::Forat', );
|
||||||
|
|
||||||
failAndExit("Required modules are missing, running no more checks.") if $missingModule;
|
failAndExit("Required modules are missing, running no more checks.") if $missingModule;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,11 +27,6 @@ is(WebGUI::Utility::commify(10), "10", 'commify() - no comma needed');
|
||||||
is(WebGUI::Utility::commify(1000), "1,000", 'commify() - single comma');
|
is(WebGUI::Utility::commify(1000), "1,000", 'commify() - single comma');
|
||||||
is(WebGUI::Utility::commify(10000000), "10,000,000", 'commify() - multiple commas');
|
is(WebGUI::Utility::commify(10000000), "10,000,000", 'commify() - multiple commas');
|
||||||
|
|
||||||
# formatBytes
|
|
||||||
is(WebGUI::Utility::formatBytes(10), '10 B', 'formatBytes() - bytes');
|
|
||||||
is(WebGUI::Utility::formatBytes(4300), '4 kB', 'formatBytes() - kilobytes');
|
|
||||||
is(WebGUI::Utility::formatBytes(1700000), '2 MB', 'formatBytes() - megabytes');
|
|
||||||
|
|
||||||
# isBetween
|
# isBetween
|
||||||
ok(WebGUI::Utility::isBetween(0,-1,1), 'isBetween() - negative and positive range');
|
ok(WebGUI::Utility::isBetween(0,-1,1), 'isBetween() - negative and positive range');
|
||||||
ok(WebGUI::Utility::isBetween(0,1,-1), 'isBetween() - negative and positive range, reversed');
|
ok(WebGUI::Utility::isBetween(0,1,-1), 'isBetween() - negative and positive range, reversed');
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue