Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^3: Interface creation

by daxim (Chaplain)
on Aug 27, 2013 at 13:43 UTC ( #1051134=note: print w/replies, xml ) Need Help??

in reply to Re^2: Interface creation
in thread Interface creation

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=""> <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, [],[]]; } };

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1051134]
[Cow1337killr]: Welcome, Kanvee.

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2017-02-23 00:44 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (338 votes). Check out past polls.