flesh out and publically document the cli API of Web::Simple::Application
[catagits/Web-Simple.git] / t / request_mode_heuristics.t
CommitLineData
f11512a9 1use strictures;
2
3use Test::More;
4use Web::Simple::Application;
5use Socket;
6
7run();
8done_testing;
9
10sub run {
11
12 my $a = Web::Simple::Application->new;
13
14 my ( $cli, $cgi, $fcgi, $test ) = qw( cli cgi fcgi test );
15
16 my $res;
17 no warnings 'redefine';
18 local *Web::Simple::Application::_run_fcgi = sub { $res = "fcgi" };
19 local *Web::Simple::Application::_run_cgi = sub { $res = "cgi" };
ca469730 20 local *Web::Simple::Application::run_cli = sub { $res = "cli" };
f11512a9 21 use strictures;
22
23 {
24 $a->run;
25 is $res, "cli", "empty invocation goes to CLI mode";
26 }
27
28 SKIP: {
29 skip "windows does not support the needed socket manipulation", 2 if $^O eq 'MSWin32' or $^O eq 'cygwin';
30 {
31 socket my $socket, AF_INET, SOCK_STREAM, 0 or die "socket: $!";
32 open my $old_in, '<&STDIN' or die "open: $!";
33 open STDIN, '<&', $socket or die "open: $!";
34 $a->run;
35 is $res, "fcgi", "STDIN being a socket means FCGI";
36 open STDIN, '<&', $old_in or die "open: $!";
37 }
38
39 {
40 local $ENV{GATEWAY_INTERFACE} = "CGI 1.1";
41 socket my $socket, AF_INET, SOCK_STREAM, 0 or die "socket: $!";
42 open my $old_in, '<&STDIN' or die "open: $!";
43 open STDIN, '<&', $socket or die "open: $!";
44 $a->run;
45 isnt $res, "fcgi", "STDIN being a socket doesn't mean FCGI if GATEWAY_INTERFACE is set";
46 open STDIN, '<&', $old_in or die "open: $!";
47 }
48 }
49
50 return;
51}