Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Stuff
Friday, August 10th, 2007 at 3:24:52pm MDT 

  1. #############################################################################
  2.  
  3. sub getPage {
  4.     my $session     = shift;    # The session object
  5.     my $asset       = shift;    # The asset object
  6.     my $page        = shift;    # The page subroutine
  7.     my $paramsRef   = shift;    # A hashref of params
  8.     my $optionsRef  = shift;    # A hashref of options
  9.                                 # args      => Array ref of args to the page sub
  10.                                 # user      => A user object to set
  11.                                 # userId    => A user ID to set, "user" takes
  12.                                 #              precedence
  13.  
  14.     #!!! GETTING COOKIES WITH WebGUI::PseudoRequest DOESNT WORK, SO WE USE
  15.     # THIS AS A WORKAROUND
  16.     $session->http->{_http}->{noHeader} = 1;
  17.    
  18.     # Open a buffer as a filehandle
  19.     my $buffer  = "";#  = IO::String->new;
  20.     open my $output, ">", \$buffer or die "Couldn't open memory buffer as filehandle: $@";
  21.     $session->output->setHandle($output);
  22.     #$session->output->setHandle($buffer);
  23.  
  24.     # Set the appropriate user
  25.     my $oldUser     = $session->user;
  26.     if ($optionsRef->{user}) {
  27.         $session->user({ user => $optionsRef->{user} });
  28.     }
  29.     elsif ($optionsRef->{userId}) {
  30.         $session->user({ userId => $optionsRef->{userId} });
  31.     }
  32.     $session->user->uncache;
  33.  
  34.     # Create a new request object
  35.     my $oldRequest  = $session->request;
  36.     my $request     = WebGUI::PseudoRequest->new;
  37.     $request->setup_param($paramsRef);
  38.     $session->{_request} = $request;
  39.  
  40.     # Fill the buffer
  41.     my $returnedContent = $asset->$page(@{$optionsRef->{args}});
  42.     if ($returnedContent && $returnedContent ne "chunked") {
  43.         print $output $returnedContent;
  44.     }
  45.  
  46.     close $output;
  47.    
  48.     # Restore the former user and request
  49.     $session->user({ user => $oldUser });
  50.     $session->{_request} = $oldRequest;
  51.  
  52.     #!!! RESTORE THE WORKAROUND
  53.     delete $session->http->{_http}->{noHeader};
  54.  
  55.     # Return the page's output
  56.     return $buffer;
  57. }

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.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



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.