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