diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2013-07-30 13:39:34 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2013-07-30 13:39:34 +0000 |
commit | 74e30d582ac01d80a7f1b28af247d0a5ee913d55 (patch) | |
tree | 2fdf53fd16ae0708e1180e4da06bea72a02175f0 /t/lib/CPANServer.pm | |
download | CPAN-Mini-Inject-tarball-master.tar.gz |
CPAN-Mini-Inject-0.33HEADCPAN-Mini-Inject-0.33master
Diffstat (limited to 't/lib/CPANServer.pm')
-rw-r--r-- | t/lib/CPANServer.pm | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/t/lib/CPANServer.pm b/t/lib/CPANServer.pm new file mode 100644 index 0000000..90a5cc9 --- /dev/null +++ b/t/lib/CPANServer.pm @@ -0,0 +1,46 @@ +package CPANServer; + +use strict; +use warnings; +use base qw(HTTP::Server::Simple::CGI); +use File::Spec::Functions; + +sub handle_request { + my $self = shift; + my $cgi = shift; + + my $file = ( split( '/', $cgi->path_info ) )[-1]; + $file = 'index.html' unless ( $file ); + open( INFILE, catfile( 't', 'html', $file ) ) + or die "Can't open file $file: $@"; + print $_ while ( <INFILE> ); + close( INFILE ); +} + +our %env_mapping = ( + protocol => "SERVER_PROTOCOL", + localport => "SERVER_PORT", + localname => "SERVER_NAME", + path => "PATH_INFO", + request_uri => "REQUEST_URI", + method => "REQUEST_METHOD", + peeraddr => "REMOTE_ADDR", + peername => "REMOTE_HOST", + query_string => "QUERY_STRING", +); + +sub setup { + no warnings 'uninitialized'; + my $self = shift; + + while ( my ( $item, $value ) = splice @_, 0, 2 ) { + if ( $self->can( $item ) ) { + $self->$item( $value ); + } + if ( my $k = $env_mapping{$item} ) { + $ENV{$k} = $value; + } + } +} + +1; |