1 package Maypole::HTTPD;
5 use base 'HTTP::Server::Simple::CGI';
6 use HTTP::Server::Simple::Static;
7 use Maypole::Constants;
8 use UNIVERSAL::require;
10 # signal to Maypole::Application
11 BEGIN { $ENV{MAYPOLE_HTTPD} = 1 }
17 Maypole::HTTPD - Stand alone HTTPD for running Maypole Applications
22 my $httpd=Maypole::HTTPD->new(module=>"BeerDB");
27 This is a stand-alone HTTPD for running your Maypole Applications.
33 The constructor. Takes a hash of arguments. Currently supported:
34 port - TCP port to listen to
35 module - Maypole application Module name.
40 my ($class, %args) = @_;
41 my $self = $class->SUPER::new($args{port});
42 $self->module($args{module});
43 #eval "use $self->{module}";
45 $self->module->require or die "Couldn't load driver: $@";
46 $self->module->config->uri_base("http://localhost:".$self->port."/");
52 Accessor for application module.
58 $self->{'module'} = shift if (@_);
59 return ( $self->{'module'} );
64 Handles the actual request processing. Should not be called directly.
73 my $path = $cgi->url( -absolute => 1, -path_info => 1 );
75 if ($path =~ m|^/static|)
81 $rv = $self->module->run;
85 print "HTTP/1.1 200 OK\n";
86 $self->module->output_now;
89 elsif ($rv == DECLINED)
91 return $self->serve_static($cgi,"./");
95 print "HTTP/1.1 404 Not Found\n\nPage not found";
108 Marcus Ramberg, E<lt>marcus@thefeed.no<gt>
109 Based on Simon Cozens' original implementation.
111 =head1 COPYRIGHT AND LICENSE
113 Copyright 2004 by Marcus Ramberg
116 This library is free software; you can redistribute it and/or modify
117 it under the same terms as Perl itself.