NAME
Gantry::Server - HTTP::Server::Simple::CGI subclass providing stand alone server
SYNOPSIS
#!/usr/bin/perl
use strict;
use Gantry::Server;
use lib '/home/myhome/lib';
use YourApp qw{ -Engine=CGI -TemplateEngine=Default };
my $cgi_engine = Gantry::Engine::CGI->new();
$cgi_engine->add_location( '/', 'YourApp' );
my $server = Gantry::Server->new();
# pass a port number to the above constructor if you don't want 8080.
$server->set_engine_object( $cgi_engine );
$server->run();
DESCRIPTION
This module subclasses HTTP::Server::Simple::CGI to provide a stand alone server for any Gantry app. Pretend you are deploying to a CGI environment, but replace
$cgi_engine->dispatch();
with
use Gantry::Server;
my $server = Gantry::Server->new();
$server->set_engine_object( $cgi_engine );
$server->run();
Note that you must call set_engine_object before calling run, and you must pass it a valid Gantry::Engine::CGI object with the proper locations and config definitions.
By default, your server will start on port 8080. If you want a different port, pass it to the constructor. You can generate the above script, with port control, in bigtop by doing this in your config section:
config {
engine CGI;
CGI Gantry { with_server 1; }
#...
}
app YourApp {
#...
}
METHODS
- set_engine_object
-
You must call this before calling run. Pass it a Gantry::Engine::CGI object.
- run
-
This starts the server and never returns.
- handler
-
This method overrides the parent version to avoid taking form parameters prematurely.
- handle_request
-
This method functions as a little web server processing http requests (but it leans heavily on HTTP::Server::Simple::CGI).
- handle_request_test
-
This method pretends to be a web server, but only handles a single request before returning. This is useful for testing your Gantry app without having to use sockets.
- handle_request_test_post
-
This is the same as handle_request_test, but it treats the request as a POST. This is mainly used for form testing.
- handle_request_test_xml
-
This method is like
handle_request_test
, but for SOAP packets. Call it with the location you want to hit and the XML packet to PUT there. Returns whatever the server returns. - net_server
-
Retrieves the defined Net::Sever engine type
- set_net_server
-
optionaly you can set a Net::Sever engine type ( see Net::Server ).
$server->set_net_server( 'Net::Server::PreForkSimple' );
- setup_server_url
-
Builds and sets the SERVER_URL environment variable.
AUTHOR
Phil Crow <philcrow2000@yahoo.com>
COPYRIGHT and LICENSE
Copyright (c) 2006, Phil Crow.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.