SCGI.pm

filter: Statementstmt 100% 28 / 28 Branchbran 70.0% 7 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 4 / 4 totaltotal 94.0% 47 / 50 CC 7 SCAR 10.7
CC
7
Cov
92%
new
5.1
accept
3.0
BEGIN
1.0
CRAP 2.9
« SCGI/Request.pm ↑ Summary
1 package SCGI;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 our $VERSION = 0.6;
7  
8 5 ▶use SCGI::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 =head1 NAME
13  
14 SCGI
15  
16 =head1 DESCRIPTION
17  
18 This module is for implementing an SCGI interface for an application server.
19  
20 =head1 SYNOPISIS
21  
22 use SCGI;
23 use IO::Socket;
24
25 my $socket = IO::Socket::INET->new(Listen => 5, ReuseAddr => 1, LocalPort => 8080)
26 or die "cannot bind to port 8080: $!";
27
28 my $scgi = SCGI->new($socket, blocking => 1);
29
30 while (my $request = $scgi->accept) {
31 $request->read_env;
32 read $request->connection, my $body, $request->env->{CONTENT_LENGTH};
33 #
34 print $request->connection "Content-Type: text/plain\n\nHello!\n";
35 }
36  
37 =head2 public methods
38  
39 =over
40  
41 =item new
42  
43 Takes a socket followed by a set of options (key value pairs) and returns a new SCGI listener. Currently the only supported option is blocking, to indicate that the socket blocks and that the library should not treat it accordingly. By default blocking is false. (NOTE: blocking is now a named rather than positional parameter. Using as a positional parameter will produce a warning in this version and will throw an exception in the next version).
44  
45 =cut
46  
47 2 ▶sub new {
Subroutine new: called CC=5 SCAR=16.3
Pod documented
48 2 my ($class, $socket) = (shift, shift);
49 2 ▶ croak "key without value passed to SCGI->new"
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 0 2 2
50 if @_ % 2;
51 2 my %options = @_;
52 2 for my $option (keys %options) {
53 1 ▶ croak "unknown option $option" unless grep $_ eq $option, qw(blocking);
Branch: 1 branch
BranchTrueFalseTotal
unless grep(($_ eq $option), "blocking") 0 1 1
54 }
55 2 ▶ bless {socket => $socket, blocking => $options{blocking} ? 1 : 0}, $class;
Branch: 1 branch
BranchTrueFalseTotal
$options{'blocking'} ? : 1 1 2
56 }
57  
58 =item accept
59  
60 Accepts a connection from the socket and returns an C<L<SCGI::Request>> for it.
61  
62 =cut
63  
64 6 ▶sub accept {
Subroutine accept: called CC=3 SCAR=11.0
Pod documented
65 6 my ($this) = @_;
66 6 ▶ my $connection = $this->socket->accept or return;
Branch: 1 branch
BranchTrueFalseTotal
my $connection = $this->socket->accept or return 6 0 6
67 6 ▶ $connection->blocking(0) unless $this->blocking;
Branch: 1 branch
BranchTrueFalseTotal
unless $this->blocking 4 2 6
68 6 SCGI::Request->_new($connection, $this->blocking);
69 }
70  
71 =item socket
72  
73 Returns the socket that was passed to the constructor.
74  
75 =cut
76  
77 6 ▶sub socket {
Subroutine socket: called CC=1 SCAR=0.0
Pod documented
78 6 my ($this) = @_;
79 6 $this->{socket};
80 }
81  
82 =item blocking
83  
84 Returns true if it was indicated that the socket should be blocking when the SCGI object was created.
85  
86 =cut
87  
88 12 ▶sub blocking {
Subroutine blocking: called CC=1 SCAR=0.0
Pod documented
89 12 my ($this) = @_;
90 12 $this->{blocking};
91 }
92  
93 5 1;
94  
95 __END__
« SCGI/Request.pm ↑ Summary