More refactoring and documentation improvements
This commit is contained in:
parent
b7e7d5b936
commit
10e8d1898d
8 changed files with 140 additions and 47 deletions
50
lib/WebGUI/Middleware/Session.pm
Normal file
50
lib/WebGUI/Middleware/Session.pm
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
package WebGUI::Middleware::Session;
|
||||
use strict;
|
||||
use parent qw(Plack::Middleware);
|
||||
use WebGUI::Config;
|
||||
use WebGUI::Session;
|
||||
|
||||
use Plack::Util::Accessor qw( config );
|
||||
|
||||
=head1 NAME
|
||||
|
||||
WebGUI::Middleware::Session - Opens and closes the per-request WebGUI::Session
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This is PSGI middleware for WebGUI that instantiates, opens and closes the
|
||||
L<WebGUI::Session> object. It does this as early and as late as possible, so
|
||||
that all intermediate middleware (and the WebGUI app itself) can grab
|
||||
the session out of the PSGI env hash:
|
||||
|
||||
$env->{'webgui.session'};
|
||||
|
||||
and not worry about closing it.
|
||||
|
||||
=cut
|
||||
|
||||
sub call {
|
||||
my ( $self, $env ) = @_;
|
||||
|
||||
my $config = $self->config or die 'Mandatory config parameter missing';
|
||||
|
||||
# Open the Session
|
||||
$env->{'webgui.session'} = WebGUI::Session->open( $config->getWebguiRoot, $config, $env );
|
||||
|
||||
# Run the app
|
||||
my $res = $self->app->($env);
|
||||
|
||||
# Use callback style response
|
||||
return $self->response_cb(
|
||||
$res,
|
||||
sub {
|
||||
my $res = shift;
|
||||
|
||||
# Close the Session
|
||||
$env->{'webgui.session'}->close();
|
||||
delete $env->{'webgui.session'};
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
@ -145,7 +145,7 @@ sub close {
|
|||
|
||||
# Kill circular references. The literal list is so that the order
|
||||
# can be explicitly shuffled as necessary.
|
||||
foreach my $key (qw/_asset _datetime _icon _slave _db _env _form _http _id _output _os _privilege _scratch _setting _stow _style _url _user _var _cache _errorHandler/) {
|
||||
foreach my $key (qw/_asset _datetime _icon _slave _db _env _form _http _id _output _os _privilege _scratch _setting _stow _style _url _user _var _cache _errorHandler _response _request/) {
|
||||
delete $self->{$key};
|
||||
}
|
||||
}
|
||||
|
|
@ -463,8 +463,8 @@ sub open {
|
|||
$self->{_request} = $request;
|
||||
$self->{_response} = $request->new_response( 200 );
|
||||
|
||||
# TODO: it might be nice to set a default Content-type here, but we can't until Assets can override it again
|
||||
# $self->{_response} = $request->new_response( 200 );#, [ 'Content-type' => 'text/html; charset=UTF-8' ] );
|
||||
# TODO: it might be nice to set a default Content-Type here, but we can't until Assets can override it again
|
||||
# $self->{_response} = $request->new_response( 200 );#, [ 'Content-Type' => 'text/html; charset=UTF-8' ] );
|
||||
|
||||
# Use the WebGUI::Session::Request object to look up the sessionId from cookies, if it
|
||||
# wasn't given explicitly
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue