| 1 | package UR::Service::WebServer::Server; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use base 'HTTP::Server::PSGI'; | ||
| 6 | |||
| 7 | # Override new because the default constructor doesn't accept a 'port' argument of | ||
| 8 | # undef to make the system pick a port | ||
| 9 | sub new { | ||
| 10 | my($class, %args) = @_; | ||
| 11 | |||
| 12 | my %supplied_port_arg; | ||
| 13 | if (exists $args{port}) { | ||
| 14 | $supplied_port_arg{port} = delete $args{port}; | ||
| 15 | } | ||
| 16 | |||
| 17 | my $self = $class->SUPER::new(%args); | ||
| 18 | if (%supplied_port_arg) { | ||
| 19 | $self->{port} = $supplied_port_arg{port}; | ||
| 20 | } | ||
| 21 | return $self; | ||
| 22 | } | ||
| 23 | |||
| 24 | sub listen_sock { | ||
| 25 | return shift->{listen_sock}; | ||
| 26 | } | ||
| 27 | |||
| 28 | # pre-fill read data for the test | ||
| 29 | sub buffer_input { | ||
| 30 | my $self = shift; | ||
| 31 | $self->{__buffer_input__} = shift; | ||
| 32 | } | ||
| 33 | |||
| 34 | sub read_timeout { | ||
| 35 | my $self = shift; | ||
| 36 | my($sock, $buf, $len, $off, $timeout) = @_; | ||
| 37 | if ($self->{__buffer_input__}) { | ||
| 38 | $$buf = ref $self->{__buffer_input__} | ||
| 39 | ? $self->{__buffer_input__}->() | ||
| 40 | : $self->{__buffer_input__}; | ||
| 41 | delete $self->{__buffer_input__}; | ||
| 42 | return length($$buf); | ||
| 43 | } | ||
| 44 | $self->SUPER::read_timeout(@_); | ||
| 45 | } | ||
| 46 | |||
| 47 | 1; | ||
| 48 | |||
| 49 |