line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Maypole::HTTPD; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
900
|
use base 'HTTP::Server::Simple'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1026
|
|
4
|
1
|
|
|
1
|
|
26343
|
use HTTP::Server::Simple::Static; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use Maypole::HTTPD::Frontend; |
6
|
|
|
|
|
|
|
use Maypole::Constants; |
7
|
|
|
|
|
|
|
use UNIVERSAL::require; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.1'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Maypole::HTTPD - Stand alone HTTPD for running Maypole Applications |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
use Maypole::HTTPD; |
18
|
|
|
|
|
|
|
my $httpd=Maypole::HTTPD->new(module=>"BeerDB"); |
19
|
|
|
|
|
|
|
$httpd->run(); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
This is a stand-alone HTTPD for running your maypole Applications. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head2 new |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
The constructor. Takes a hash of arguments. Currently supported: |
30
|
|
|
|
|
|
|
port - TCP port to listen to |
31
|
|
|
|
|
|
|
module - Maypole application Module name. |
32
|
|
|
|
|
|
|
=cut |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub new { |
35
|
|
|
|
|
|
|
my ($class,%args) =@_; |
36
|
|
|
|
|
|
|
my $self=$class->SUPER::new($args{port}); |
37
|
|
|
|
|
|
|
$self->module($args{module}); |
38
|
|
|
|
|
|
|
eval "use $self->module"; |
39
|
|
|
|
|
|
|
$self->module->config->uri_base("http://localhost:".$self->port."/"); |
40
|
|
|
|
|
|
|
$self->steal(); |
41
|
|
|
|
|
|
|
return $self; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head2 module |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Accessor for application module. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub module { |
51
|
|
|
|
|
|
|
my $self = shift; |
52
|
|
|
|
|
|
|
$self->{'module'} = shift if (@_); |
53
|
|
|
|
|
|
|
return ( $self->{'module'} ); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 handle_request |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Handles the actual request processing. Should not be called directly. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=cut |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub handle_request { |
63
|
|
|
|
|
|
|
my ($self,$cgi) = @_; |
64
|
|
|
|
|
|
|
my $rv; |
65
|
|
|
|
|
|
|
my $path = $cgi->url( -absolute => 1, -path_info => 1 ); |
66
|
|
|
|
|
|
|
if ($path =~ m|^/static|) { |
67
|
|
|
|
|
|
|
$rv=DECLINED; |
68
|
|
|
|
|
|
|
} else { |
69
|
|
|
|
|
|
|
$rv = $self->module->run(); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
if ($rv == OK) { |
72
|
|
|
|
|
|
|
print "HTTP/1.1 200 OK\n"; |
73
|
|
|
|
|
|
|
$self->module->output_now; |
74
|
|
|
|
|
|
|
return; |
75
|
|
|
|
|
|
|
} elsif ($rv == DECLINED) { |
76
|
|
|
|
|
|
|
return $self->serve_static($cgi,"./"); |
77
|
|
|
|
|
|
|
} else { |
78
|
|
|
|
|
|
|
print "HTTP/1.1 404 Not Found\n\nPage not found"; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 steal |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Adds Maypole::HTTPD::Frontend to @ISA of Maypole::Application, so it |
85
|
|
|
|
|
|
|
will be used for the maypole application. Is called from the constructor. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub steal { |
90
|
|
|
|
|
|
|
my ($self) = @_; |
91
|
|
|
|
|
|
|
#my $module=$self->module; |
92
|
|
|
|
|
|
|
no strict; |
93
|
|
|
|
|
|
|
local *isa = *{"Maypole::Application::ISA"}; |
94
|
|
|
|
|
|
|
pop @isa;push @isa, "Maypole::HTTPD::Frontend" |
95
|
|
|
|
|
|
|
unless $isa[0] eq "Maypole::HTTPD::Frontend"; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
1; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 SEE ALSO |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
L |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 AUTHOR |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Marcus Ramberg, Emarcus@thefeed.no |
107
|
|
|
|
|
|
|
Based on Simon Cozens' original implementation. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Copyright 2004 by Marcus Ramberg |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
115
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |