Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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


Comment on Re^3: Interface creation
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2014-07-10 11:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (207 votes), past polls