Writing a CGI Script

AUTHOR

stmuk

You want to write a simple CGI to parse a form and display it

(This example uses the more modern and faster variation PSGI and runs standalone on localhost at port 8080 and depends on 'HTTP::Easy' and 'Web' being installed from the ecosystem)

UTF-8

' ], [ $form ]]; } else { return [ 200, [ 'Content-Type' => 'text/html;charset=UTF-8' ], [ "<html>hello {$name}</html>" ] ]; } }

#!/usr/bin/env raku

use v6;



use HTTP::Easy::PSGI;
use Web::Request;

my $http = HTTP::Easy::PSGI.new(:port(8080));

my $form = qq :to 'EOT';
<html>
  <form>
    Enter your name
    <input name="name" type="text">
    <input type="submit">
  </form>
</html>
EOT

# entry point
my $app = sub (%env) {
    my $req = Web::Request.new(%env);

    if !(my $name = $req.get('name')).so {
        # no CGI param passed so display form
        return [ 200, [ 'Content-Type' => 'text/html;charset

$http.handle($app);

# vim: expandtab shiftwidth=4 ft=perl6

See Also

01strings

Perl 6 Cookbook: Introduction to Strings

01strings

Substrings

01strings

Swapping values

01strings

Converting between characters and numbers.

01strings

Using Named Unicode Chars

01strings

Reversing a String by Word or Character

01strings

Upper/Lower Case

01strings

Trimming whitespace from both ends of a string

01strings

Soundex Matching

02numbers

Valid Number

02numbers

Convert to/from Roman Numerals

02numbers

Logarithms

02numbers

Complex Numbers

02numbers

Convert Bases

03dates-and-times

Today's Date

03dates-and-times

DateTime to Epoch Seconds

03dates-and-times

Epoch Seconds to DateTime

03dates-and-times

Adding and Subtracting Dates

03dates-and-times

Subtracting Two Dates From Each other

03dates-and-times

From date to week of year, month of year, day of year

03dates-and-times

Hi-Res Timings

04arrays

Specifying a list in your program

04arrays

Printing a list with commas

04arrays

Iterating Over an Array

05hashes

Traversing a hash

06pattern-matching

Copy and substitute simultaneously

06pattern-matching

Matching alphabetic wide characters

07file-access

Opening a file

08file-contents

Count File Lines

08file-contents

Process every word in a file

08file-contents

Read file lines backwards

09directories

Get/Set Filetime

09directories

Delete File

09directories

Copy/Move File

09directories

Process all files in a directory

09directories

Get list of files matching a pattern

09directories

Process files recursively

09directories

Splitting up a filename

09directories

Process files lazy

10subroutines

Accessing subroutine arguments

13classes-objects-and-ties

Constructing an object

13classes-objects-and-ties

Managing Instance data

13classes-objects-and-ties

Managing Instance data

13classes-objects-and-ties

Overloading operators

14database-access

Executing SQL with DBIish

15interactivity

Parsing program arguments

15interactivity

Test whether program is interactive or not

15interactivity

Clear the screen

15interactivity

Change text colour

16processes

Timeout Operation

16processes

List Signals

16processes

Send a signal to a process

16processes

Catch ctrl-c

17sockets

Writing a TCP Client

17sockets

Writing a TCP Server

20web-automation

Fetch uri

README.md

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.