NAME

Para::Frame::Request - The request from the client

DESCRIPTION

Para::Frame::Request is the central class for most operations. The current request object can be reached as $Para::Frame::REQ.

new

get_by_id

  Para::Frame::Request->get_by_id( $id )

get_subreq_by_id

  $req->get_by_id( $id )

Looks for the id in the subrequests of the req, recursive.

init

new_subrequest

  $req->new_subrequest( \%args, \&code, @params )

Sets up a subrequest using /new_minimal.

We switch to the new request
calls the &code (in scalar context) with the req as the first param, followed by @params
switch back to the callng request
returns the first of the returned values

args:

  site: A L<Para::Frame::Site> object. If defined, and the host
differs from that of the current request, we sets ut a background
request that can be used to query apache about uri2file translations.

  user: A L<Para::Frame::User> object. Defaults to the current user.

A subrequest must make sure that it finishes BEFORE the parent, unless it is decoupled to become a background request.

The parent will be made to wait for the subrequest result. But if the subrequest sets up additional jobs, you have to take care of either makeing it a background request or making the parent wait.

We creates the new request with /new_minimal and sends the \%args to /minimal_init.

release_subreq

new_bgrequest

Sets up a background request using new_minimal

http_init

Initializes the /http_init request for http requests

new_minimal

Used for background jobs, without a calling browser client

minimal_init

  $req->minimal_init( \%args )

Initializes the /new_minimal request. A smaller version of init.

args:

  site: The site for the request, set by L</set_site>. Optional.

  language: The language for the request, set by L</set_language>,
that will use a default if no input.

  user: The L<Para::Frame::User> to be in this request. Defaults to
using L<Para::Frame/bg_user_code> for getting the user.

Returns: The request

id

  $req->id

Returns the request number

q

  $req->q

Returns the CGI object.

TODO: Replace CGI module with URI::QueryParam

session

  $req->session

Returns the Para::Frame::Session object.

env

  $req->env

Returns a hashref of the environment variables passed given by Apache for the request.

client

  $req->client

Returns the object representing the connection to the client that made this request. The stringification of this object is used as a key in several places.

cookies

  $req->cookies

Returns the Para::Frame::Cookies object for this request.

result

  $req->result

Returns the Para::Frame::Result object for this request.

result_message

  $req->result_message( $message )

Sends a message to the result, or just the log if no result object.

language

  $req->language

Returns the L10N language handler object.

set_language

  $req->set_language()

  $req->set_language( $language_in )

This is called during the initiation of the request.

Calls Para::Frame::L10N/set or a subclass theriof defined in Para::Frame/l10n_class.

response

  $req->response

Returns the Para::Frame::Request::Response object.

response_if_existing

page

  $req->page

Returns a Para::Frame::File object from Para::Frame::Request::Response/page.

original

  $req->original

If this is a subrequest; return the original request.

equals

  $req->equals( $req2 )

Returns true if the two requests are the same.

user

  $req->user

Returns the Para::Frame::User object. Or probably a object of a subclass of that class.

This is short for calling $req->session->user

Returns undef if the request doesn't have a session.

require_root_access

  $req->require_root_access

Throws a denied exception if the current user hasn't root access

change

  $req->change

Returns the Para::Frame::Change object for this request.

is_from_client

  $req->is_from_client

Returns true if this request is from a client and not a background server job or something else. Not true for direct http_requests, as those are meant for ajax/json.

dirconfig

  $req->dirconfig

Returns the dirconfig hashref. See Apache/SERVER CONFIGURATION INFORMATION dir_config.

Params:

site: Used by Para::Frame::Request/reset_response. If site is set to ignore, the Para::Frame::Client will decline all requests and let thenext apache handler take care of it.

action: Used by /setup_jobs

port: Used by Para::Frame::Client

backup_port: Used by Para::Frame::Client

backup_redirect: Used by Para::Frame::Client

backup: Used by Para::Frame::Client

find: Used by Para::Frame::File/template

loadpage: Used by Para::Frame/handle_request. If loadpage is set to no, a loadpage will not be sent.

do_forward: Used by Para::Frame::Request::Response/send_output. If do_forward is set to no, we will not redirect, even on errors.

Example for a .htaccess PerlSetVar site ignore

browser

  $req->browser

Returns the HTTP::BrowserDetect object for the request.

header_only

set_header_only

is_backend

uploaded

  $req->uploaded( $filefiled )

Calls Para::Frame::Uploaded/new

in_yield

  $req->in_yield

Returns true if this request has yielded for another request, or for reading from the socket

uri2file

  $req->uri2file( $url )

  $req->uri2file( $url, $file )

  $req->uri2file( $url, undef, $return_partial )

This does the Apache URL to filename translation

Directory URLs must end in '/'. The URL '' is not valid.

The answer is cached. Remove an url from the cache with uri2file_clear.

If given a $file uses that as a translation and caches is.

(This method may have to create a pseudoclient connection to get the information.)

If $return_partial is true, we will return a part of the path instead of throwing an exception.

Returns:

The file WITH '/' for dirs (NB! CHANGED)

Exceptions:

Throws a notfound exception if translation results in a file where the last part differs from the one sent in. That would be the case when the directory doesn't exist or for unsupported url translations.

uri2file_clear

  $req->uri2file( $url )

  $req->uri2file()

Clears the $url from the cache for the $req host.

With no $url, clear all uris from the cache.

normalized_url

  $req->normalized_url( $url )

  $req->normalized_url( $url, $params )

Gives the proper version of the URL. Ending index.tt will be removed. This is used for redirecting (forward) the browser if nesessary.

$url must be the path part as a string.

params:

  no_check

Returns:

  the path part as a string

setup_jobs

  $req->setup_jobs()

Set up things from params.

add_action

prepend_action

add_job

  $req->add_job($method, @args)

This will run $req-<$method(@args) when the job is processed.

For a custom job, use /run_code.

Remember du add the job /after_jobs if this is the last job.

add_background_job

  $req->add_background_job( $label, \&code, @params )

Runs the &code in the background with the given @params.

$label is used for keeping metadata about what jobs are in queue.

Background jobs are done in between regular requests.

The $req is given as the first param.

Example:

  my $idle_job = sub
  {
      my( $req, $thing ) = @_;
      debug "I'm idling now like a $thing...";
  };
  $req->add_background_job( 'ideling', $idle_job, 'Kangaroo' );

prepend_background_job

  $req->prepend_background_job( $label, \&code, @params )

May still take a lot of time since the prepended background job is then appended to the list of current jobs.

run_code

  $req->run_code( $label, $coderef, @args )

This will run &{$coderef}($req, @args).

Usually set up by

  $req->add_job('run_code', $label, $coderef, @args);

See /add_job.

run_action

If the action requires the user to login, a new Para::Frame::Request::Response will be created for the /login.tt template.

If the session object can Para::Frame::Session/go_login and the method returns true, it will be used instead of a redirection to /login.tt template.

after_jobs

done

in_last_job

in_loadpage

in_ajax

in_precompile

error_backtrack

referer_path

  $req->referer_path

Returns the LOCAL referer. Just the path part. If the referer was from another website, fall back to default.

(This gives the previous caller page)

Returns the URL path part as a string.

referer_query

  $req->referer_query

Returns the escaped form of the query string. Should give the same result regardless of GET or POST was used.

Defaults to ''.

referer_with_query

  $req->referer_with_query

Returns referer with query string as a string.

This combines /referer and /referer_query.

send_to_daemon

talk_to_daemon

send_code

release_active_request

get_cmd_val

may_yield

  $req->may_yield

  $req->may_yield( $wait )

Calls /yield only if there was more than 2 seconds since the last yield.

For operations taking a lot of time, insert this in places there a change of request is safe.

yield

  $req->yield

  $req->yield( $wait )

This calls the main loop, changing all global variables if another request is processed. Then that request is done, we return. If there was nothing to do, we will come back here quickly.

If $wait is given, waits a maximum of that amount of time for another request. Mostly to be used if we know that another request is coming and we want that to be handled before we continue.

http_host

  $req->http_host

Returns the host name the client requested. It tells with which of the alternatives names the site was requested. This string does not contain 'http://'.

http_port

  $req->http_port

Returns the port the client used in this request.

http_scheme

  $req->http_scheme

Returns the scheme the client used in this request.

Either http or https

http_if_modified_since

  $req->http_if_modified_since

Returns the time as an Para::Frame::Time object.

If no such time was given with the request, returns undef.

client_ip

  $req->client_ip

Returns the ip address of the client as a string with dot-separated numbers.

set_site

  $req->set_site( $site )

Sets the site to use for this request.

$site should be the name of a registred Para::Frame::Site or a site object.

The site must use the same host as the request.

The method works similarly to Para::Frame::File/set_site

Returns: The site object

site

  $req->site

The site for the request is used for actions.

It may not be the same as the site of the response page as given by $req->page->site. But will in most cases be the same since it's set in the same way as the initial site for the response page.

But in some cases there will be no page (as for background jobs), and thus no page site.

Make sure to set the request site along with the page site, if it's to change and any futher actions in the request should use that new site.

Returns the Para::Frame::Site object for this request.

host_from_env

host

  $req->host

Returns the host name used for accessing this host. Includes :$port if port differs from 80.

host_without_port

  $req->host_without_port

Returns the host name used for accessing this host, without the port part.

host_with_port

  $req->host_with_port

Returns the host name used for accessing this host, with the port part.

create_fork

  $req->create_fork

Creates a fork.

In PARENT, returns a Para::Frame::Child object.

In CHILD, returnt a Para::Frame::Child::Result object.

Then the child returns. The hook child_result is runt with the Para::Frame::Result object as the param after $req.

You must make sure to exit the child. This is supposed to be done by the Para::Frame::Result/result method.

The hook on_fork is run in the CHILD just after the Para::Frame::Result object is created.

Example 1 uses Para::Frame::Child::Result/on_return. Example 2 uses Para::Frame::Child/yield. The first method (example 1) is preferred as it is safer and faster in certain cases.

Example 1:

  my $fork = $req->create_fork;
  if( $fork->in_child )
  {
      # Do the stuff...
      $fork->on_return('process_my_data');
      $fork->return($my_result);
  }
  return "";

  sub process_my_data
  {
      my( $result ) = @_;
      # Do more stuff
      return "All done now";
  }

Example 2:

  my $fork = $req->create_fork;
  if( $fork->in_child )
  {
      # Do the stuff...
      $fork->return($my_result);
  }
  $fork->yield; # let other requests run
  return $fork->result;

register_child

get_child_result

run_hook

  $req->run_hook( $label, @args );

logging

waiting

nop

cancelled

active

cancel

note

  $req->note( $text )

Sending text to show during loading of a page.

Usable for progress indication.

set_page

set_page_path

set_response_path

set_response

  $req->set_response( $url, \%args )

set_error_response

set_error_response_path

reset_response

  $req->reset_response()

Uses current /page if existing.

If this is the first time, sets the URL from the req as the original page. The original page can be retrieved via /original_response.

Should be used if we may want to use another template based on a changed language or something else in the context that has changed.

Calls /set_response and returns that response.

error_page_selected

  $req->error_page_selected

True if an error page has been selected

error_page_not_selected

  $req->error_page_not_selected

True if an error page has not been selected

original_response

  $req->original_response

original_url

  $req->original_url

original_url_string

  $req->original_url_string

original_url_with_query

  $req->original_url_with_query

original_url_params

  $req->original_url_params

The query string passed as part of the URL

Not including any POST data.

Used by Para::Frame::Request::Response/page_url_path_with_query_and_reqnum

Returns: the unparsed string, after the '?', as given by $ENV{'QUERY_STRING'}. Saved on Req startup.

original_content_type_string

original_status

handle_error

Sets the Para::Frame::Request::Response appropriate for the error.

If the session object can Para::Frame::Session/go_login and the method returns true, it will be used instead of a redirection to /login.tt template.

send_stored_result

server_report

AUTHOR

Jonas Liljegren <jonas@paranormal.se>

SEE ALSO

Para::Frame