checkpoint
This commit is contained in:
parent
9e535846d5
commit
c0abcc3e4a
3 changed files with 78 additions and 33 deletions
|
|
@ -1,7 +1,8 @@
|
|||
package WebGUI::Response;
|
||||
use strict;
|
||||
use parent qw(Plack::Response);
|
||||
|
||||
use Plack::Util::Accessor qw(streaming);
|
||||
use Plack::Util::Accessor qw(streaming writer streamer);
|
||||
|
||||
=head2 DESCRIPTION
|
||||
|
||||
|
|
@ -13,7 +14,16 @@ sub stream {
|
|||
my $self = shift;
|
||||
my $streamer = shift;
|
||||
$self->streaming(1);
|
||||
$self->body($streamer);
|
||||
$self->streamer($streamer);
|
||||
}
|
||||
|
||||
sub stream_write {
|
||||
my $self = shift;
|
||||
if (!$self->streaming) {
|
||||
Carp::carp("stream_write can only be called inside streaming response");
|
||||
return;
|
||||
}
|
||||
$self->writer->write(@_);
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
@ -90,18 +90,20 @@ sub print {
|
|||
my $content = shift;
|
||||
my $skipMacros = shift || !($self->session->http->getMimeType =~ /^text/);
|
||||
WebGUI::Macro::process($self->session, \$content) unless $skipMacros;
|
||||
|
||||
# Initialise response body if it's empty
|
||||
$self->session->response->body([]) if !$self->session->response->body;
|
||||
|
||||
my $body = $self->session->response->body;
|
||||
if (ref $body ne 'ARRAY') {
|
||||
Carp::carp("Response body is not an ARRAY, it's a " . ref $body);
|
||||
return;
|
||||
my $handle = $self->{_handle};
|
||||
if (defined $handle) {
|
||||
print $handle $content;
|
||||
}
|
||||
elsif ($self->session->response) {
|
||||
if ($self->session->response->streaming) {
|
||||
$self->session->response->stream_write($content);
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
print $content;
|
||||
}
|
||||
push @{ $body }, $content;
|
||||
|
||||
# TODO - put in IO bound delayed response
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue