Finish up the file upload handling by PseudoRequest. If you
call $pseudoRequest->uploadFiles with a list of filenames, it will populate the upload method with upload objects, so that Storage->getFileFromFormPost will have an object with all the right methods. t/Storage.t tests this incidently. It occurs to me that we need tests for our PseudoRequest module, and it needs POD, and it should probably be rewritten using Class::InsideOut for good form.
This commit is contained in:
parent
4de53b2de9
commit
1cf78f5321
2 changed files with 72 additions and 2 deletions
|
|
@ -1,5 +1,7 @@
|
|||
package WebGUI::PseudoRequest;
|
||||
|
||||
use strict;
|
||||
|
||||
package WebGUI::PseudoRequest::Headers;
|
||||
|
||||
sub new {
|
||||
|
|
@ -22,6 +24,55 @@ sub fetch {
|
|||
return $self->{headers};
|
||||
}
|
||||
|
||||
package WebGUI::PseudoRequest::Upload;
|
||||
|
||||
sub new {
|
||||
my $this = shift;
|
||||
my $class = ref($this) || $this;
|
||||
my $self = {
|
||||
fh => undef,
|
||||
size => 0,
|
||||
filename => '',
|
||||
};
|
||||
my $file = shift;
|
||||
if ($file and -e $file) {
|
||||
$self->{filename} = $file;
|
||||
$self->{size} = (stat $file)[7];
|
||||
open my $fh, '<' . $file or
|
||||
die "Unable to open $file for reading and creating a filehandle: $!\n";
|
||||
$self->{fh} = $fh;
|
||||
}
|
||||
bless $self, $class;
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub fh {
|
||||
my $self = shift;
|
||||
my $value = shift;
|
||||
if (defined $value) {
|
||||
$self->{fh} = $value;
|
||||
}
|
||||
return $self->{fh};
|
||||
}
|
||||
|
||||
sub filename {
|
||||
my $self = shift;
|
||||
my $value = shift;
|
||||
if (defined $value) {
|
||||
$self->{filename} = $value;
|
||||
}
|
||||
return $self->{filename};
|
||||
}
|
||||
|
||||
sub size {
|
||||
my $self = shift;
|
||||
my $value = shift;
|
||||
if (defined $value) {
|
||||
$self->{size} = $value;
|
||||
}
|
||||
return $self->{size};
|
||||
}
|
||||
|
||||
package WebGUI::PseudoRequest;
|
||||
|
||||
sub new {
|
||||
|
|
@ -156,6 +207,20 @@ sub upload {
|
|||
return @{ $self->{uploads}->{$formName} };
|
||||
}
|
||||
|
||||
sub uploadFiles {
|
||||
my $self = shift;
|
||||
my $formName = shift;
|
||||
my $filesToUpload = shift;
|
||||
return unless $formName;
|
||||
return unless scalar $filesToUpload;
|
||||
my @uploadObjects = ();
|
||||
foreach my $file (@{ $filesToUpload }) {
|
||||
my $upload = WebGUI::PseudoRequest::Upload->new($file);
|
||||
push @uploadObjects, $upload;
|
||||
}
|
||||
$self->upload($formName, \@uploadObjects);
|
||||
}
|
||||
|
||||
sub uri {
|
||||
my $self = shift;
|
||||
my $value = shift;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue