The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

App::Context::HTTP - context in which we are currently running

SYNOPSIS

   # ... official way to get a Context object ...
   use App;
   $context = App->context();
   $config = $context->config();   # get the configuration
   $config->dispatch_events();     # dispatch events

   # ... alternative way (used internally) ...
   use App::Context::HTTP;
   $context = App::Context::HTTP->new();

DESCRIPTION

A Context class models the environment (aka "context) in which the current process is running. For the App::Context::HTTP class, this models any of the web application runtime environments which employ the HTTP protocol and produce HTML pages as output. This includes CGI, mod_perl, FastCGI, etc. The difference between these environments is not in the Context but in the implementation of the Request and Response objects.

Protected Methods:

The following methods are intended to be called by subclasses of the current class.

init()

The init() method is called from within the standard Context constructor.

The init() method sets debug flags.

    * Signature: $context->init($args)
    * Param:     $args            hash{string} [in]
    * Return:    void
    * Throws:    App::Exception
    * Since:     0.01

    Sample Usage: 

    $context->init($args);

Protected Methods

These methods are considered protected because no class is ever supposed to call them. They may however be called by the context-specific drivers.

dispatch_events()

The dispatch_events() method is called by the CGI script in order to get the Context object rolling. It causes the program to process the CGI request, interpret and dispatch encoded events in the request and exit.

In concept, the dispatch_events() method would not return until all events for a Session were dispatched. However, the reality of the CGI context is that events associated with a Session occur in many different processes over different CGI requests. Therefore, the CGI Context implements the dispatch_events() method to return after processing all of the events of a single request, assuming that it will be called again when the next CGI request is received.

    * Signature: $context->dispatch_events()
    * Param:     void
    * Return:    void
    * Throws:    App::Exception
    * Since:     0.01

    Sample Usage: 

    $context->dispatch_events();

send_response()

    * Signature: $context->send_response()
    * Param:     void
    * Return:    void
    * Throws:    App::Exception
    * Since:     0.01

    Sample Usage: 

    $context->send_response();

request()

    * Signature: $context->request()
    * Param:     void
    * Return:    void
    * Throws:    App::Exception
    * Since:     0.01

    Sample Usage: 

    $context->request();

The request() method gets the current Request being handled in the Context.

response()

    * Signature: $context->response()
    * Param:     void
    * Return:    void
    * Throws:    App::Exception
    * Since:     0.01

    Sample Usage: 

    $context->response();

The response() method gets the current Request being handled in the Context.

user_agent()

The user_agent() method returns a UserAgent objects which is primarily useful to see what capabilities the user agent (browser) supports.

    * Signature: $user_agent = $context->user_agent();
    * Param:  void
    * Return: $user_agent    App::UserAgent
    * Throws: <none>
    * Since:  0.01

    Sample Usage: 

    $user_agent = $context->user_agent();

Public Methods:

user()

The user() method returns the username of the authenticated user. The special name, "guest", refers to the unauthenticated (anonymous) user.

    * Signature: $username = $self->user();
    * Param:  void
    * Return: string
    * Throws: <none>
    * Since:  0.01

    Sample Usage: 

    $username = $context->user();

In a request/response environment, this turns out to be a convenience method which gets the authenticated user from the current Request object.