line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/env perl |
2
|
|
|
|
|
|
|
package HTTP::Server::Simple::WebDAO; |
3
|
1
|
|
|
1
|
|
25759
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
29
|
|
5
|
1
|
|
|
1
|
|
1216
|
use HTTP::Server::Simple::CGI; |
|
1
|
|
|
|
|
31263
|
|
|
1
|
|
|
|
|
37
|
|
6
|
1
|
|
|
1
|
|
12
|
use base qw/HTTP::Server::Simple::CGI/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
88
|
|
7
|
1
|
|
|
1
|
|
659
|
use WebDAO; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use WebDAO::Util; |
9
|
|
|
|
|
|
|
use WebDAO::Engine; |
10
|
|
|
|
|
|
|
use WebDAO::Session; |
11
|
|
|
|
|
|
|
use WebDAO::Store::Abstract; |
12
|
|
|
|
|
|
|
use vars qw($VERSION); |
13
|
|
|
|
|
|
|
$VERSION = '0.03'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
HTTP::Server::Simple::WebDAO - WebDAO handler for HTTP::Server::Simple |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
HTTP::Server::Simple::WebDAO; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $srv = new HTTP::Server::Simple::WebDAO::($port); |
24
|
|
|
|
|
|
|
$srv->set_config( wdEngine => "Plosurin::HTTP", wdDebug => 3 ); |
25
|
|
|
|
|
|
|
$srv->run(); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 DESCRIPTION |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
HTTP::Server::Simple::WebDAO is a HTTP::Server::Simple based HTTP server |
30
|
|
|
|
|
|
|
that can run WebDAO applications. This module only depends on |
31
|
|
|
|
|
|
|
L, which itself doesn't depend on any non-core |
32
|
|
|
|
|
|
|
modules so it's best to be used as an embedded web server. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 SEE ALSO |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
L, L |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 AUTHOR |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Zahatski Aliaksandr |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 LICENSE |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Copyright 2011-2012 by Zahatski Aliaksandr |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
48
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub new { |
53
|
|
|
|
|
|
|
my $class = shift; |
54
|
|
|
|
|
|
|
my $self = $class->SUPER::new(@_); |
55
|
|
|
|
|
|
|
$self->set_config; |
56
|
|
|
|
|
|
|
return $self; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub set_config { |
61
|
|
|
|
|
|
|
my $self = shift; |
62
|
|
|
|
|
|
|
my %args = @_; |
63
|
|
|
|
|
|
|
while ( my ( $k, $v ) = each %args ) { |
64
|
|
|
|
|
|
|
$self->{$k} = $v; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
$ENV{wdStore} ||= $args{wdStore}; |
67
|
|
|
|
|
|
|
$ENV{wdSession} ||= $args{wdSession}; |
68
|
|
|
|
|
|
|
$ENV{wdEngine} ||= $args{wdEngine}; |
69
|
|
|
|
|
|
|
#preload defaults |
70
|
|
|
|
|
|
|
$self->{ini} = WebDAO::Util::get_classes(__env => \%ENV, __preload=>1); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
$self; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub handle_request { |
76
|
|
|
|
|
|
|
my ( $self, $cgi ) = @_; |
77
|
|
|
|
|
|
|
my $ini = $self->{ini}; |
78
|
|
|
|
|
|
|
my $store_obj = "$ini->{wdStore}"->new( |
79
|
|
|
|
|
|
|
%{ $ini->{wdStorePar} } |
80
|
|
|
|
|
|
|
); |
81
|
|
|
|
|
|
|
my $sess = "$ini->{wdSession}"->new( |
82
|
|
|
|
|
|
|
%{ $ini->{wdSessionPar} }, |
83
|
|
|
|
|
|
|
store => $store_obj, |
84
|
|
|
|
|
|
|
cv => HTTP::Server::Simple::WebDAO::CVcgi->new(env=>\%ENV) |
85
|
|
|
|
|
|
|
); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my $eng = "$ini->{wdEngine}"->new( |
88
|
|
|
|
|
|
|
%{ $ini->{wdEnginePar} }, |
89
|
|
|
|
|
|
|
session => $sess, |
90
|
|
|
|
|
|
|
); |
91
|
|
|
|
|
|
|
$ENV{wdDebug} = $self->{wdDebug} if exists $self->{wdDebug}; |
92
|
|
|
|
|
|
|
$sess->ExecEngine($eng); |
93
|
|
|
|
|
|
|
$sess->destroy; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
package HTTP::Server::Simple::WebDAO::CVcgi; |
97
|
|
|
|
|
|
|
use strict; |
98
|
|
|
|
|
|
|
use warnings; |
99
|
|
|
|
|
|
|
use WebDAO::CVfcgi; |
100
|
|
|
|
|
|
|
use WebDAO::Util; |
101
|
|
|
|
|
|
|
use base qw/WebDAO::CVfcgi/; |
102
|
|
|
|
|
|
|
sub new { |
103
|
|
|
|
|
|
|
my $class = shift; |
104
|
|
|
|
|
|
|
return $class->WebDAO::CV::new(@_, writer=> sub { |
105
|
|
|
|
|
|
|
my $code = $_[0]->[0]; |
106
|
|
|
|
|
|
|
my $headers_ref = $_[0]->[1]; |
107
|
|
|
|
|
|
|
my $fd = new WebDAO::Fcgi::Writer:: headers=>$headers_ref; |
108
|
|
|
|
|
|
|
my $message = $WebDAO::Util::HTTPStatusCode{$code}; |
109
|
|
|
|
|
|
|
my $header_str= "HTTP/1.0 $code $message\015\012"; |
110
|
|
|
|
|
|
|
while ( my ($header, $value) = splice( @$headers_ref, 0, 2) ) { |
111
|
|
|
|
|
|
|
$header_str .= "$header: $value\015\012" |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
$header_str .="\015\012"; |
114
|
|
|
|
|
|
|
$fd->write($header_str); |
115
|
|
|
|
|
|
|
return $fd |
116
|
|
|
|
|
|
|
} ) |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
package HTTP::Server::Simple::WebDAO; |
120
|
|
|
|
|
|
|
1; |