1package SCGI; 2 3use strict; 4use warnings; 5 6our $VERSION = 0.6; 7 8use SCGI::Request; 9 10use Carp; 11 12=head1 NAME 13 14SCGI 15 16=head1 DESCRIPTION 17 18This 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 43Takes 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 47sub new { 48 my ($class, $socket) = (shift, shift); 49 croak "key without value passed to SCGI->new" 50 if @_ % 2; 51 my %options = @_; 52 for my $option (keys %options) { 53 croak "unknown option $option" unless grep $_ eq $option, qw(blocking); 54 } 55 bless {socket => $socket, blocking => $options{blocking} ? 1 : 0}, $class; 56} 57 58=item accept 59 60Accepts a connection from the socket and returns an C<L<SCGI::Request>> for it. 61 62=cut 63 64sub accept { 65 my ($this) = @_; 66 my $connection = $this->socket->accept or return; 67 $connection->blocking(0) unless $this->blocking; 68 SCGI::Request->_new($connection, $this->blocking); 69} 70 71=item socket 72 73Returns the socket that was passed to the constructor. 74 75=cut 76 77sub socket { 78 my ($this) = @_; 79 $this->{socket}; 80} 81 82=item blocking 83 84Returns true if it was indicated that the socket should be blocking when the SCGI object was created. 85 86=cut 87 88sub blocking { 89 my ($this) = @_; 90 $this->{blocking}; 91} 92 931; 94 95__END__ 96 97=back 98 99=head1 KNOWN ISSUES 100 101The SCGI Apache2 module had a bug (for me at least), which resulted in segmentation faults. This appeared after version 1.2 (the version in Debian Sarge) and was fixed in 1.10. 102 103The SCGI Apache2 module has a bug where certain headers can be repeated. This is still present in version 1.10. A patch has been accepted and this issue should be resolved in the next release. This modulenow issues a warning on a repeated header, rather than throwing an exception as in the previous version. 104 105=head1 AUTHOR 106 107Thomas Yandell L<mailto:tom+scgi@vipercode.com> 108 109=head1 COPYRIGHT 110 111Copyright 2005, 2006 Viper Code Limited. All rights reserved. 112 113=head1 LICENSE 114 115This file is part of SCGI (perl SCGI library). 116 117This program is free software; you can redistribute it and/or 118modify it under the same terms as Perl itself. 119 120=cut 121