Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

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]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2018-01-17 02:18 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (194 votes). Check out past polls.