cleaning up some imports
This commit is contained in:
parent
8fb275850c
commit
d9c1f88eab
8 changed files with 57 additions and 61 deletions
|
|
@ -27,7 +27,7 @@ use Apache2::RequestIO;
|
|||
use Apache2::RequestUtil ();
|
||||
use Apache2::ServerUtil ();
|
||||
use APR::Request::Apache2;
|
||||
use MIME::Base64;
|
||||
use MIME::Base64 ();
|
||||
use WebGUI::Config;
|
||||
use WebGUI::Pluggable;
|
||||
use WebGUI::Session;
|
||||
|
|
|
|||
|
|
@ -21,8 +21,6 @@ use WebGUI::Cache;
|
|||
use WebGUI::Storage;
|
||||
use WebGUI::SQL;
|
||||
use WebGUI::Utility;
|
||||
use FileHandle;
|
||||
|
||||
|
||||
|
||||
=head1 NAME
|
||||
|
|
@ -536,15 +534,12 @@ sub www_edit {
|
|||
sub exportHtml_view {
|
||||
my $self = shift;
|
||||
my $path = $self->getStorageLocation->getPath($self->get('filename'));
|
||||
my $fh = eval { FileHandle->new($path) };
|
||||
defined($fh) or return "";
|
||||
binmode $fh or ($fh->close, return "");
|
||||
my $block;
|
||||
while (read($fh, $block, 16384) > 0) {
|
||||
$self->session->output->print($block, 1);
|
||||
}
|
||||
$fh->close;
|
||||
return 'chunked';
|
||||
open my $fh, '<:raw', $path or return "";
|
||||
while ( read $fh, my $block, 16384 ) {
|
||||
$self->session->output->print($block, 1);
|
||||
}
|
||||
close $fh;
|
||||
return 'chunked';
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -15,9 +15,8 @@ package WebGUI::Asset;
|
|||
=cut
|
||||
|
||||
use strict;
|
||||
use File::Basename;
|
||||
use File::Path;
|
||||
use FileHandle;
|
||||
use File::Basename ();
|
||||
use File::Path ();
|
||||
use Path::Class;
|
||||
use Scalar::Util 'looks_like_number';
|
||||
use WebGUI::International;
|
||||
|
|
@ -92,7 +91,7 @@ sub exportCheckPath {
|
|||
# now that we know that it's defined and not an empty string, test if it exists.
|
||||
if(!-e $exportPath) {
|
||||
# it doesn't exist; let's try making it
|
||||
eval { mkpath( [$exportPath] ) };
|
||||
eval { File::Path::mkpath( [$exportPath] ) };
|
||||
if($@) {
|
||||
WebGUI::Error->throw(error => "can't create exportPath $exportPath");
|
||||
}
|
||||
|
|
@ -543,7 +542,7 @@ sub exportGetUrlAsPath {
|
|||
return Path::Class::File->new($exportPath, @pathComponents, $filename, $index);
|
||||
}
|
||||
else { # got a dot
|
||||
my $extension = (fileparse($filename, qr/[^.]*$/))[2]; # get just the extension
|
||||
my $extension = (File::Basename::fileparse($filename, qr/[^.]*$/))[2]; # get just the extension
|
||||
|
||||
# check if the file type is recognised by apache. if it is, return it
|
||||
# as-is. if not, slap on the directory separator, $index, and return
|
||||
|
|
@ -748,7 +747,7 @@ sub exportWriteFile {
|
|||
my $dest = $self->exportGetUrlAsPath;
|
||||
my $parent = $dest->parent;
|
||||
|
||||
eval { mkpath($parent->absolute->stringify) };
|
||||
eval { File::Path::mkpath($parent->absolute->stringify) };
|
||||
if($@) {
|
||||
WebGUI::Error->throw(error => "could not make directory " . $parent->absolute->stringify);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ package WebGUI::Asset;
|
|||
=cut
|
||||
|
||||
use strict;
|
||||
use JSON;
|
||||
use JSON ();
|
||||
use WebGUI::Storage;
|
||||
|
||||
=head1 NAME
|
||||
|
|
|
|||
|
|
@ -15,12 +15,11 @@ package WebGUI::Cache;
|
|||
=cut
|
||||
|
||||
use strict;
|
||||
use File::Path;
|
||||
use File::Path ();
|
||||
use HTTP::Headers;
|
||||
use HTTP::Request;
|
||||
use LWP::UserAgent;
|
||||
use Digest::MD5;
|
||||
use Encode;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -92,7 +91,7 @@ Flushes the caching system. Must be overridden.
|
|||
|
||||
sub flush {
|
||||
my $self = shift;
|
||||
rmtree($self->session->config->get("uploadsPath")."/temp");
|
||||
File::Path::rmtree($self->session->config->get("uploadsPath")."/temp");
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -131,7 +130,6 @@ A subdivider to store this cache under. When building your own cache plug-in def
|
|||
=cut
|
||||
|
||||
sub new {
|
||||
my $cache;
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
if ($session->config->get("cacheType") eq "WebGUI::Cache::Database") {
|
||||
|
|
@ -170,7 +168,8 @@ sub parseKey {
|
|||
}
|
||||
foreach my $part (@key) {
|
||||
# convert to octets, then md5 them
|
||||
$part = Digest::MD5::md5_base64(Encode::encode_utf8($part));
|
||||
utf8::encode($part);
|
||||
$part = Digest::MD5::md5_base64($part);
|
||||
$part =~ tr{/}{-};
|
||||
}
|
||||
return join('/', @key);
|
||||
|
|
@ -185,8 +184,7 @@ Returns a reference to the current session.
|
|||
=cut
|
||||
|
||||
sub session {
|
||||
my $self = shift;
|
||||
return $self->{_session};
|
||||
$_[0]->{_session};
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@ package WebGUI::Cache::FileCache;
|
|||
=cut
|
||||
|
||||
use strict;
|
||||
use Storable qw(nstore retrieve);
|
||||
use File::Path;
|
||||
use File::Find;
|
||||
use Storable ();
|
||||
use File::Path ();
|
||||
use File::Find ();
|
||||
|
||||
our @ISA = qw(WebGUI::Cache);
|
||||
|
||||
|
|
@ -54,7 +54,7 @@ sub delete {
|
|||
my $self = shift;
|
||||
my $folder = $self->getFolder;
|
||||
if (-e $folder) {
|
||||
rmtree($folder);
|
||||
File::Path::rmtree($folder);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -74,7 +74,7 @@ sub deleteChunk {
|
|||
my $self = shift;
|
||||
my $folder = $self->getNamespaceRoot."/".$self->parseKey(shift);
|
||||
if (-e $folder) {
|
||||
rmtree($folder);
|
||||
File::Path::rmtree($folder);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -91,7 +91,7 @@ sub flush {
|
|||
$self->SUPER::flush();
|
||||
my $folder = $self->getNamespaceRoot;
|
||||
if (-e $folder) {
|
||||
rmtree($folder);
|
||||
File::Path::rmtree($folder);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -110,9 +110,9 @@ sub get {
|
|||
if (-e $folder."/expires" && -e $folder."/cache" && open(my $FILE,"<",$folder."/expires")) {
|
||||
my $expires = <$FILE>;
|
||||
close($FILE);
|
||||
return undef if ($expires < $self->session->datetime->time());
|
||||
return undef if ($expires < time);
|
||||
my $value;
|
||||
eval {$value = retrieve($folder."/cache")};
|
||||
eval {$value = Storable::retrieve($folder."/cache")};
|
||||
if (ref $value eq "SCALAR") {
|
||||
return $$value;
|
||||
} else {
|
||||
|
|
@ -155,7 +155,7 @@ sub getNamespaceRoot {
|
|||
$root .= "/WebGUICache";
|
||||
}
|
||||
$root .= "/".$self->{_namespace};
|
||||
return $root;
|
||||
return $root;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -167,24 +167,29 @@ Returns the size (in bytes) of the current cache under this namespace. Consequen
|
|||
=cut
|
||||
|
||||
sub getNamespaceSize {
|
||||
my $self = shift;
|
||||
my $expiresModifier = shift || 0;
|
||||
$self->session->stow->set("cacheSize", 0);
|
||||
File::Find::find({no_chdir=>1, wanted=> sub {
|
||||
return undef unless $File::Find::name =~ m/^(.*)expires$/;
|
||||
my $dir = $1;
|
||||
if (open(my $FILE,"<",$dir."/expires")) {
|
||||
my $expires = <$FILE>;
|
||||
close($FILE);
|
||||
if ($expires <$self->session->datetime->time()+$expiresModifier) {
|
||||
rmtree($dir);
|
||||
} else {
|
||||
$self->session->stow->set("cacheSize", $self->session->stow->get("cacheSize") + -s $dir.'cache');
|
||||
}
|
||||
}
|
||||
}
|
||||
}, $self->getNamespaceRoot);
|
||||
return $self->session->stow->get("cacheSize");
|
||||
my $self = shift;
|
||||
my $expiresModifier = shift || 0;
|
||||
my $cacheSize = 0;
|
||||
File::Find::find({
|
||||
no_chdir => 1,
|
||||
wanted => sub {
|
||||
return
|
||||
unless $File::Find::name =~ m/expires$/;
|
||||
if ( open my $FILE, "<", $File::Find::name ) {
|
||||
my $expires = <$FILE>;
|
||||
close $FILE;
|
||||
if ($expires < time + $expiresModifier) {
|
||||
File::Path::rmtree($File::Find::dir);
|
||||
$File::Find::prune = 1;
|
||||
return
|
||||
}
|
||||
else {
|
||||
$cacheSize += -s $File::Find::dir.'/cache';
|
||||
}
|
||||
}
|
||||
},
|
||||
}, $self->getNamespaceRoot);
|
||||
return $cacheSize;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -241,7 +246,7 @@ sub set {
|
|||
umask(0000);
|
||||
my $path = $self->getFolder();
|
||||
unless (-e $path) {
|
||||
eval {mkpath($path,0)};
|
||||
eval {File::Path::mkpath($path,0)};
|
||||
if ($@) {
|
||||
$self->session->errorHandler->error("Couldn't create cache folder: ".$path." : ".$@);
|
||||
return undef;
|
||||
|
|
@ -253,10 +258,10 @@ sub set {
|
|||
} else {
|
||||
$value = $content;
|
||||
}
|
||||
nstore($value, $path."/cache");
|
||||
open(my $FILE,">",$path."/expires");
|
||||
print $FILE $self->session->datetime->time()+$ttl;
|
||||
close($FILE);
|
||||
Storable::nstore($value, $path."/cache");
|
||||
open my $FILE, ">", $path."/expires";
|
||||
print $FILE time + $ttl;
|
||||
close $FILE;
|
||||
umask($oldumask);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ package WebGUI::Content::AjaxI18N;
|
|||
=cut
|
||||
|
||||
use strict;
|
||||
use JSON;
|
||||
use JSON ();
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
|
|||
|
|
@ -169,8 +169,7 @@ Returns a reference to the current session.
|
|||
=cut
|
||||
|
||||
sub session {
|
||||
my $self = shift;
|
||||
return $self->{_session};
|
||||
$_[0]->{_session};
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue