-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplack.pl
95 lines (84 loc) · 2.54 KB
/
plack.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# Running Plack on Android using ASE
# Originally written by Stevan Little (minor cleanups by Sawyer X)
# Copied here with explicit permission
# (thank you Stevan :)
# Stevan also notes that he had to make the following modules available
# in order to make this work:
# - Devel-StackTrace-1.22.tar.gz
# - Devel-StackTrace-AsHTML-0.09.tar.gz
# - FileHandle.pm
# - HTTP-Body-1.07.tar.gz
# - HTTP-Server-Simple-0.42.tar.gz
# - Hash-MultiValue-0.08.tar.gz
# - PathTools-3.31.tar.gz
# - PerlIO.pm
# - Plack-0.9929.tar.gz
# - Pod-Parser-1.38.tar.gz
# - Time-Local-1.1901.tar.gz
# - Try-Tiny-0.04.tar.gz
# - URI-1.54.tar.gz
# - integer.pm
# - libwww-perl-5.834.tar.gz
# - parent-0.223.tar.gz
use strict;
use warnings;
BEGIN {
my @modules = qw/
Devel::StackTrace Devel::StackTrace::AsHTML FileHandle HTTP::Body
HTTP::Server::Simple Hash::MultiValue PathTools PerlIO Plack Pod::Parser
Time::Local Try::Tiny URI integer LWP parent
/;
foreach my $module (@modules) {
eval "use $module";
$@ and die "You do not have $module installed, sorry.\n"; }
}
}
use Android;
use Plack::Runner;
use Plack::Request;
my $droid = Android->new();
my $runner = Plack::Runner->new();
$runner->parse_options( qw(
--server HTTP::Server::PSGI
--port 8888
) );
$runner->run( sub {
my $env = shift;
my $req = Plack::Request->new( $env );
if ( my $phone_number = $req->param('phone_number') ) {
$a->callNumber( $phone_number );
return [
200,
[ 'Content-Type' => 'text/html' ],
[ qq(
<html>
<head>
<title>Plack On Droid</title>
</head>
<body>
<p>Calling $phone_number ...</p>
</body>
</html>
) ],
];
} else {
return [
200,
[ 'Content-Type' => 'text/html' ],
[ q(
<html>
<head>
<title>Plack On Droid</title>
</head>
<body>
<form>
Enter a phone number to call<br/>
<input type="text" name="phone_number" />
<input type="submit" value="Go" />
</form>
</body>
</html>
) ],
];
}
} );