blib/lib/HTTP/Server/Simple/WebDAO.pm

filter: Statementstmt 92.5% 25 / 27 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod n/a totaltotal 94.4% 34 / 36 SCAR 0.0
CC
1
Cov
93%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Build ↑ Summary
1 #!/usr/bin/env perl
2 package HTTP::Server::Simple::WebDAO;
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use HTTP::Server::Simple::CGI;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use base qw/HTTP::Server::Simple::CGI/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use WebDAO;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use WebDAO::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use WebDAO::Engine;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use WebDAO::Session;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use WebDAO::Store::Abstract;
Subroutine BEGIN: called CC=1 SCAR=2.6
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<HTTP::Server::Simple>, 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<HTTP::Server::Simple>, L<WebDAO>
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;
« Build ↑ Summary