Refactored Request/Response into WebGUI::Session::

This commit is contained in:
Patrick Donelan 2010-04-08 21:30:55 -04:00
parent 1ad2f0cfd7
commit b7e7d5b936
5 changed files with 117 additions and 90 deletions

View file

@ -0,0 +1,40 @@
package WebGUI::Session::Request;
use strict;
use parent qw(Plack::Request);
use WebGUI::Session::Response;
=head1 SYNOPSIS
my $session = WebGUI::Session->open(...);
my $request = $session->request;
=head1 DESCRIPTION
WebGUI's PSGI request utility class. Sub-classes L<Plack::Request>.
An instance of this object is created automatically when the L<WebGUI::Session>
is created.
=head1 METHODS
=head2 new_response ()
Creates a new L<WebGUI::Session::Response> object.
N.B. A L<WebGUI::Session::Response> object is automatically created when L<WebGUI::Session>
is instantiated, so in most cases you will not need to call this method.
See L<WebGUI::Session/response>
=cut
sub new_response {
my $self = shift;
return WebGUI::Session::Response->new(@_);
}
# This is only temporary
sub TRACE {
shift->env->{'psgi.errors'}->print(join '', @_, "\n");
}
1;

View file

@ -0,0 +1,36 @@
package WebGUI::Session::Response;
use strict;
use parent qw(Plack::Response);
use Plack::Util::Accessor qw(session streaming writer streamer);
=head1 SYNOPSIS
my $session = WebGUI::Session->open(...);
my $response = $session->response;
=head1 DESCRIPTION
WebGUI's PSGI response utility class. Sub-classes L<Plack::Response>.
An instance of this object is created automatically when the L<WebGUI::Session>
is created.
=cut
sub stream {
my $self = shift;
$self->streamer(shift);
$self->streaming(1);
}
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;