Engine/Interface/ServerSimple.pm untested

filter: Statementstmt 0.0% 0 / 38 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 52 SCAR 34.0
CC
5
Cov
0%
run
30.0
BEGIN
2.0
BEGIN
2.0
CRAP 30.0
1 package HTTP::Engine::Interface::ServerSimple;
2 use Any::Moose;
3 use HTTP::Engine::Interface
4 builder => 'NoEnv',
5 writer => {
6 response_line => 1,
7 }
8 ;
9  
10 use HTTP::Server::Simple 0.34;
11 use HTTP::Server::Simple::CGI;
12  
13 has host => (
14 is => 'ro',
15 isa => 'Str',
16 default => '127.0.0.1',
17 );
18  
19 has port => (
20 is => 'ro',
21 isa => 'Int',
22 required => 1,
23 );
24  
25 has net_server => (
26 is => 'ro',
27 isa => 'Str | Undef',
28 default => undef,
29 );
30  
31 sub run {
32 my ($self, ) = @_;
33  
34 my $headers;
35 my %setup;
36 my $server;
37 $server = any_moose('::Meta::Class')
38 ->create_anon_class(
39 superclasses => ['HTTP::Server::Simple'],
40 methods => {
41 setup => sub {
42 shift; # $self;
43 $headers = HTTP::Headers::Fast->new;
44 %setup = @_;
45 },
46 headers => sub {
47 my ( $self, $args ) = @_;
48 $headers->header(@$args) if @$args;
49 },
50 handler => sub {
51 my($host, $port) = $headers->header('Host') ?
52 split(':', $headers->header('Host')) :($setup{localname}, $setup{localport});
53 my $base = "http://${host}";
54 $base .= ":$port" if $port;
55 my $request_uri = $setup{request_uri};
56 $request_uri = '/' if $request_uri =~ m!^https?://!i;
57 my $uri = URI::WithBase->new(
58 $base . $request_uri,
59 $base . '/',
60 );
61 $self->handle_request(
62 uri => $uri,
63 connection_info => {
64 method => $setup{method},
65 protocol => $setup{protocol},
66 address => $setup{peeraddr},
67 port => $setup{localport},
68 user => undef,
69 _https_info => undef,
70 request_uri => $setup{request_uri},
71 },
72 headers => $headers,
73 _connection => {
74 env => {},
75 input_handle => \*STDIN,
76 output_handle => \*STDOUT,
77 },
78 )
79 },
80 net_server => sub { $self->net_server },
81 print_banner => sub {
82 print( __PACKAGE__
83 . " : You can connect to your server at "
84 . "http://localhost:"
85 . $self->port
86 . "/\n" );
87 },
88 },
89 cache => 1
90 )->name->new(
91 $self->port
92 );
93 $server->host($self->host);
94 $server->run;
95 }
96  
97 __INTERFACE__
98  
99 __END__