blib/lib/Froody/Server/Standalone.pm

filter: Statementstmt 43.1% 25 / 58 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 66.6% 8 / 12 Podpod 100% 3 / 3 totaltotal 43.9% 36 / 82 CC 4 SCAR 13.9
CC
4
Cov
38%
dispatcher
12.0
handle_request
6.0
config
2.0
CRAP 4.0
« blib/lib/Froody/Reflection.pm ↑ Summary blib/lib/Froody/Walker/Terse.pm »
1 package Froody::Server::Standalone;
2 5 ▶use base qw(HTTP::Server::Simple::CGI);
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 =head1 NAME
5  
6 Froody::Server::Standalone - standalone server for Froody
7  
8 =head1 SYNOPSIS
9  
10 use Froody::Server::Standalone;
11 my $server = Froody::Server::Standalone->new();
12 $server->port(4242);
13 $server->run;
14  
15 # now you'll have a froody server listening on port 4242
16  
17 =head1 DESCRIPTION
18  
19 Froody::Server::Standalone is a subvlass of HTTP::Server::Simple::CGI
20 that has been altered to serve Froody requests
21  
22 Currently it uses a global dispatcher stored in the global variable
23 $Froody::Server::Standalone::dispatcher. If no dispatcher exists when the
24 first handler comes in one is created automatically and put into this
25 variable.
26  
27 This code is very likely to change, but that's the current behavior.
28  
29 =cut
30  
31 5 ▶use Froody;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 5 ▶use HTTP::Date;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 5 ▶use Froody::Request::CGI;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 5 ▶use Froody::Dispatch;
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 5 ▶use Froody::Server;
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 sub handle_request
43 0 ▶{
Subroutine handle_request: not called CC=2 SCAR=17.9
Pod documented
44 0 my ($self, $cgi) = @_;
45
46 # what are we asking for?
47 0 my $request = Froody::Request::CGI->new($cgi);
48 0 my $type = $request->type;
49
50 # dispatch
51 0 $self->dispatcher->error_style("response");
52 0 my $response = eval { #Don't allow the server to die on unhandled exceptions.
53 0 $self->dispatcher->dispatch(
54 method => $request->method,
55 params => $request->params,
56 );
57 }; #
58
59 0 ▶ unless ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
60 # send the data back to the browser
61 0 my $method = "render_$type";
62 0 return $self->_send_bytes(
63 "200 OK",
64 Froody::Server->content_type_for_type($type),
65 $response->$method
66 );
67 } else {
68 0 $self->_send_bytes("500 Server Error", "text/plain", "$@");
69 }
70 }
71  
72 =head2 config
73  
74 =cut
75  
76 0 ▶sub config {
Subroutine config: not called CC=1 SCAR=6.9
Pod documented
77 0 my $self = shift;
78 0 $self->{_dispatcher} = Froody::Dispatch->config(@_);
79 }
80  
81 =head2 dispatcher
82  
83 =cut
84  
85 0 ▶sub dispatcher {
Subroutine dispatcher: not called CC=3 SCAR=24.8
Pod documented
86 0 my $self = shift;
87 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
88 0 $self->{_dispatcher} = shift;
89 0 return $self;
90 }
91 0 ▶ return $self->{_dispatcher} ||= Froody::Dispatch->new;
Condition0%0/3
$self->{"_dispatcher"} ||= "Froody::Dispatch"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"_dispatcher"} ||= "Froody::Dispatch"->new
$self->{"_dispatcher"} "Froody::Dispatch"->new
Truth table0%0/3
A ||= B
A= $self->{"_dispatcher"}B= "Froody::Dispatch"->new
ABresult
1X1
011
000
92 }
93  
94 sub _send_bytes
95 0 ▶{
Subroutine _send_bytes: not called CC=1 SCAR=6.9
96 0 my $self = shift;
97 0 my $status = shift;
98 0 my $content_type = shift;
99 0 my $bytes = shift;
100 0 my $time = time2str();
101
102 # server headers
103 0 print "HTTP/1.0 $status\r\n";
104  
105 # standard headers
106 0 print "Content-Type: $content_type\r\n";
107 0 print "Content-Length: ", length($bytes), "\r\n";
108  
109 # froody headers (for debugging)
110 0 print "X-Froody-Version: ".$Froody::VERSION."\r\n";
111 0 print "X-Towel: Over drain.\r\n";
112
113 # no caching
114 0 print "Cache-Control: no-cache\r\n";
115 0 print "Date: $time\r\n";
116 0 print "Expires: $time\r\n";
117
118 # seperator
119 0 print "\r\n";
120
121 # content
122 0 print $bytes;
123 0 return;
124 }
125  
126 =head1 BUGS
127  
128 None known.
129  
130 Please report any bugs you find via the CPAN RT system.
131 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Froody>
132  
133 =head1 AUTHOR
134  
135 Copyright Fotango 2005. All rights reserved.
136  
137 Please see the main L<Froody> documentation for details of who has worked
138 on this project.
139  
140 This module is free software; you can redistribute it and/or modify it under
141 the same terms as Perl itself.
142  
143 =head1 SEE ALSO
144  
145 L<Froody>, L<Froody::Dispatch>, L<Froody::Repository>
146  
147 =cut
148  
149  
150  
151 5 1;
« blib/lib/Froody/Reflection.pm ↑ Summary blib/lib/Froody/Walker/Terse.pm »