NAME

MT::App - Movable Type base web application class


SYNOPSIS

    package MT::App::Foo;
    use MT::App;
    @MT::App::Foo::ISA = qw( MT::App );
    package main;
    my $app = MT::App::Foo->new;
    $app->run;


DESCRIPTION

MT::App is the base class for Movable Type web applications. It provides support for an application running using standard CGI, or under Apache::Registry, or as a mod_perl handler. MT::App is not meant to be used directly, but rather as a base class for other web applications using the Movable Type framework (for example, MT::App::CMS).


USAGE

MT::App subclasses the MT class, which provides it access to the publishing methods in that class.

Following are the list of methods specific to MT::App:

MT::App->new

Constructs and returns a new MT::App object.

$app->run

Runs the application. This gathers the input, chooses the method to execute, executes it, and prints the output to the client.

If an error occurs during the execution of the application, run handles all of the errors thrown either through the MT::ErrorHandler or through die.

$app->login

Checks the user's credentials, first by looking for a login cookie, then by looking for the username and password CGI parameters. In both cases, the username and password are verified for validity. This method does not set the user's login cookie, however--that should be done by the caller (in most cases, the caller is the run method).

On success, returns the MT::Author object representing the author who logged in, and a boolean flag; if the boolean flag is true, it indicates the the login credentials were obtained from the CGI parameters, and thus that a cookie should be set by the caller. If the flag is false, the credentials came from an existing cookie.

On an authentication error, login removes any authentication cookies that the user might have on his or her browser, then returns undef, and the error message can be obtained from $app->errstr.

$app->send_http_header([ $content_type ])

Sends the HTTP header to the client; if $content_type is specified, the Content-Type header is set to $content_type. Otherwise, text/html is used as the default.

In a mod_perl context, this calls the Apache::send_http_header method; in a CGI context, the CGI::header method is called.

$app->print(@data)

Sends data @data to the client.

In a mod_perl context, this calls the Apache::print method; in a CGI context, data is printed directly to STDOUT.

$app->bake_cookie(%arg)

Bakes a cookie to be sent to the client.

%arg can contain any valid parameters to the new methods of CGI::Cookie (or Apache::Cookie--both take the same parameters). These include -name, -value, -path, and -expires.

If you do not include the -path parameter in %arg, it will be set automatically to $app->path (below).

In a mod_perl context, this method uses Apache::Cookie; in a CGI context, it uses CGI::Cookie.

$app->cookies

Returns a reference to a hash containing cookie objects, where the objects are either of class Apache::Cookie (in a mod_perl context) or CGI::Cookie (in a CGI context).

$app->build_page($tmpl_name, \%param)

Builds an application page to be sent to the client; the page name is specified in $tmpl_name, which should be the name of a template containing valid HTML::Template markup. \%param is a hash ref whose keys and values will be passed to HTML::Template::param for use in the template.

On success, returns a scalar containing the page to be sent to the client. On failure, returns undef, and the error message can be obtained from $app->errstr.

$app->redirect($url)

Issues a redirect to the client to the URL $url. If $url is not an absolute URL, it is prepended with the value of $app->base.

$app->base

The protocol and domain of the application. For example, with the full URI http://www.foo.com/mt/mt.cgi, this method will return http://www.foo.com.

$app->path

The path to the application directory. For example, with the full URI http://www.foo.com/mt/mt.cgi, this method will return /mt/.

$app->script

The name of the application. For example, with the full URI http://www.foo.com/mt/mt.cgi, this method will return mt.cgi.

$app->uri

The concatenation of $app->path and $app->script. For example, with the full URI http://www.foo.com/mt/mt.cgi, this method will return /mt/mt.cgi.

$app->path_info

The path_info for the request (that is, whatever is left in the URI after the URI to filename translation).

$app->log($msg)

Adds the message $msg to the activity log. The log entry will be tagged with the IP address of the client running the application (that is, of the browser that made the HTTP request), using $app->remote_ip.

$app->trace(@msg)

Adds a trace message ``@msg'' to the internal tracing mechanism; trace messages are then displayed at the top of the output page sent to the client. This is useful for debugging.

$app->remote_ip

The IP address of the client.

In a mod_perl context, this calls Apache::Connection::remote_ip; in a CGI context, this uses $ENV{REMOTE_ADDR}.


AUTHOR & COPYRIGHTS

Please see the MT manpage for author, copyright, and license information.