Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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

Comment on Re^3: Interface creation
Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1051134]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2015-10-08 21:03 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (228 votes), past polls