A small Plack application to get you started. I have not tested this code much.
Learn the basics of Web programming. Add error checking. Add HTML escaping of the output. Replace this piecewise output of HTML with templating. Consider migrating this code to a micro Web framework.
use 5.010;
use strictures;
use Plack::Request qw();
use HTTP::Status qw(HTTP_OK HTTP_METHOD_NOT_ALLOWED);
use Local::MyFastaThing qw(process_fasta);
sub html_head {
return <<'';
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>MyFastaThing Web front-end</title>
</head>
<body>
}
sub form {
my ($where_am_i) = @_;
return <<"";
<form action="$where_am_i" method="POST">
<label for="sequence">paste sequence</label>
<textarea id="sequence" name="sequence"></textarea>
<label for="fasta">upload fasta</label>
<input id="fasta" name="fasta" type="file" />
<input type="submit" />
</form>
}
sub html_tail {
return <<'';
</body>
</html>
}
my $app = sub {
my ($env) = @_;
my $req = Plack::Request->new($env);
if ('GET' eq $req->method) {
return [HTTP_OK, ['Content-Type' => 'application/xhtml+xml'],
+[html_head, form($req->uri), html_tail]];
} elsif ('POST' eq $req->method) {
return [HTTP_OK, ['Content-Type' => 'application/xhtml+xml'],
+[html_head, '<p>',
process_fasta($req->upload('fasta') // $req->body_paramete
+rs->{sequence}),
'</p>', html_tail]];
} else {
return [HTTP_METHOD_NOT_ALLOWED, [],[]];
}
};
|