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.
41 my ($class, %args) = @_;
42 my $self = $class->SUPER::new($args{port});
43 $self->module($args{module});
44 #eval "use $self->{module}";
46 $self->module->require or die "Couldn't load driver: $@";
47 $self->module->config->uri_base("http://localhost:".$self->port."/");
53 Accessor for application module.
59 $self->{'module'} = shift if (@_);
60 return ( $self->{'module'} );
65 Handles the actual request processing. Should not be called directly.
74 my $path = $cgi->url( -absolute => 1, -path_info => 1 );
76 if ($path =~ m|^/static|)
82 $rv = $self->module->run;
86 print "HTTP/1.1 200 OK\n";
87 $self->module->output_now;
90 elsif ($rv == DECLINED)
92 return $self->serve_static($cgi,"./");
96 print "HTTP/1.1 404 Not Found\n\nPage not found";
109 Marcus Ramberg, E<lt>marcus@thefeed.no<gt>
110 Based on Simon Cozens' original implementation.
112 =head1 COPYRIGHT AND LICENSE
114 Copyright 2004 by Marcus Ramberg
117 This library is free software; you can redistribute it and/or modify
118 it under the same terms as Perl itself.