| 1 | package WebDAO::Fcgi::Writer; | ||
| 2 | our $VERSION = '0.01'; | ||
| 3 | |||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | sub new { | ||
| 7 | my $class = shift; | ||
| 8 | my $self = bless( ( $#_ == 0 ) ? shift : {@_}, ref($class) || $class ); | ||
| 9 | } | ||
| 10 | sub write { shift; print STDOUT @_ } | ||
| 11 | sub close { } | ||
| 12 | sub headers { return $_[0]->{headers} } | ||
| 13 | |||
| 14 | 1; | ||
| 15 | |||
| 16 | package WebDAO::CVfcgi; | ||
| 17 | our $VERSION = '0.02'; | ||
| 18 | |||
| 19 | =head1 NAME | ||
| 20 | |||
| 21 | WebDAO::CVfcgi - FCGI adapter (FCGI > 0.68) | ||
| 22 | |||
| 23 | =head1 SYNOPSIS | ||
| 24 | |||
| 25 | =head1 DESCRIPTION | ||
| 26 | |||
| 27 | WebDAO::CVfcgi - FCGI adapter for FCGI version > 0.68 | ||
| 28 | |||
| 29 | =cut | ||
| 30 | |||
| 31 | |||
| 32 | |||
| 33 | use base qw( WebDAO::CV ); | ||
| 34 | use strict; | ||
| 35 | use warnings; | ||
| 36 | use WebDAO::Util; | ||
| 37 | sub new { | ||
| 38 | my $class = shift; | ||
| 39 | return $class->SUPER::new(@_, writer=> sub { | ||
| 40 | my $code = $_[0]->[0]; | ||
| 41 | my $headers_ref = $_[0]->[1]; | ||
| 42 | my $fd = new WebDAO::Fcgi::Writer:: headers=>$headers_ref; | ||
| 43 | my $message = $WebDAO::Util::HTTPStatusCode{$code}; | ||
| 44 | my $header_str= "Status: $code $message\015\012"; | ||
| 45 | while ( my ($header, $value) = splice( @$headers_ref, 0, 2) ) { | ||
| 46 | $value = '' unless defined $value; | ||
| 47 | $header_str .= "$header: $value\015\012" | ||
| 48 | } | ||
| 49 | $header_str .="\015\012"; | ||
| 50 | $fd->write($header_str); | ||
| 51 | return $fd | ||
| 52 | } ) | ||
| 53 | } | ||
| 54 | sub print { | ||
| 55 | my $self = shift; | ||
| 56 | foreach my $str (@_) { | ||
| 57 | next unless defined $str; | ||
| 58 | utf8::encode( $str) if utf8::is_utf8($str); | ||
| 59 | print $str; | ||
| 60 | } | ||
| 61 | } | ||
| 62 | 1; | ||
| 63 | package WebDAO::CVfcgiold; | ||
| 64 | our $VERSION = '0.01'; | ||
| 65 | use base qw/WebDAO::CVfcgi/; | ||
| 66 | sub print { | ||
| 67 | my $self = shift; | ||
| 68 | print for @_; | ||
| 69 | } | ||
| 70 | 1; | ||
| 71 | __DATA__ | ||
| 72 | |||
| 73 | =head1 SEE ALSO | ||
| 74 | |||
| 75 | http://webdao.sourceforge.net | ||
| 76 | |||
| 77 | =head1 AUTHOR | ||
| 78 | |||
| 79 | Zahatski Aliaksandr, E<lt>zag@cpan.orgE<gt> | ||
| 80 | |||
| 81 | =head1 COPYRIGHT AND LICENSE | ||
| 82 | |||
| 83 | Copyright 2012 by Zahatski Aliaksandr | ||
| 84 | |||
| 85 | This library is free software; you can redistribute it and/or modify | ||
| 86 | it under the same terms as Perl itself. | ||
| 87 | |||
| 88 | =cut |