- Stuff
- Friday, August 10th, 2007 at 3:24:52pm MDT
- #############################################################################
- sub getPage {
- my $session = shift; # The session object
- my $asset = shift; # The asset object
- my $page = shift; # The page subroutine
- my $paramsRef = shift; # A hashref of params
- my $optionsRef = shift; # A hashref of options
- # args => Array ref of args to the page sub
- # user => A user object to set
- # userId => A user ID to set, "user" takes
- # precedence
- #!!! GETTING COOKIES WITH WebGUI::PseudoRequest DOESNT WORK, SO WE USE
- # THIS AS A WORKAROUND
- $session->http->{_http}->{noHeader} = 1;
- # Open a buffer as a filehandle
- my $buffer = "";# = IO::String->new;
- open my $output, ">", \$buffer or die "Couldn't open memory buffer as filehandle: $@";
- $session->output->setHandle($output);
- #$session->output->setHandle($buffer);
- # Set the appropriate user
- my $oldUser = $session->user;
- if ($optionsRef->{user}) {
- $session->user({ user => $optionsRef->{user} });
- }
- elsif ($optionsRef->{userId}) {
- $session->user({ userId => $optionsRef->{userId} });
- }
- $session->user->uncache;
- # Create a new request object
- my $oldRequest = $session->request;
- my $request = WebGUI::PseudoRequest->new;
- $request->setup_param($paramsRef);
- $session->{_request} = $request;
- # Fill the buffer
- my $returnedContent = $asset->$page(@{$optionsRef->{args}});
- if ($returnedContent && $returnedContent ne "chunked") {
- print $output $returnedContent;
- }
- close $output;
- # Restore the former user and request
- $session->user({ user => $oldUser });
- $session->{_request} = $oldRequest;
- #!!! RESTORE THE WORKAROUND
- delete $session->http->{_http}->{noHeader};
- # Return the page's output
- return $buffer;
- }
advertising
Update the Post
Either update this post and resubmit it with changes, or make a new post.
You may also comment on this post.
Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.