Skip to content

Commit

Permalink
First versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Cross committed Dec 24, 2015
0 parents commit a87ddee
Show file tree
Hide file tree
Showing 10 changed files with 198 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cgi1.cgi
@@ -0,0 +1,7 @@
#!/usr/bin/perl

use strict;
use warnings;

print "Content-type: text/plain\n\n";
print 'Hello world';
7 changes: 7 additions & 0 deletions cgi2.cgi
@@ -0,0 +1,7 @@
#!/usr/bin/perl
use strict;
use warnings;

print "Content-type: text/plain\n\n";
my $now = localtime;
print "The time is $now";
19 changes: 19 additions & 0 deletions cgi3.cgi
@@ -0,0 +1,19 @@
#!/usr/bin/perl

use strict;
use warnings;

print "Content-type: text/html\n\n";
my $now = localtime;

print <<END_HTML;
<html>
<head>
<title>Time</title>
</head>
<body>
<h1>Time</h1>
<p>The time is $now</p>
</body>
</html>
END_HTML
11 changes: 11 additions & 0 deletions cgi4.cgi
@@ -0,0 +1,11 @@
#!/usr/bin/perl -wT
use strict;
use CGI ':standard';

print header;
my $now = localtime;

print start_html(-title=>'Time'),
h1('Time'),
p("The time is $now"),
end_html;
33 changes: 33 additions & 0 deletions cgi5.cgi
@@ -0,0 +1,33 @@
#!/usr/bin/perl

use strict;
use warnings;

use CGI ':standard';

my $name = param('name');
my $age = param('age');
my $gender = param('gender');
my @hobbies = param('hobby');

my $list;

if (@hobbies) {
$list = join ', ', @hobbies;
} else {
$list = 'None';
}

print header,
start_html(-title=>$name),
h1("Welcome $name"),
p('Here are your details:'),
table(Tr(td('Name:'),
td($name)),
Tr(td('Age:'),
td($age)),
Tr(td('Gender:'),
td($gender)),
Tr(td('Hobbies:'),
td($list))),
end_html;
8 changes: 8 additions & 0 deletions psgi1.cgi
@@ -0,0 +1,8 @@
#!/usr/bin/plackup

use strict;
use warnings;

my $app = sub {
return [ 200, [ 'Content-type' => 'text/plain' ], [ 'Hello world' ] ];
};
14 changes: 14 additions & 0 deletions psgi2.cgi
@@ -0,0 +1,14 @@
#!/usr/bin/plackup

use strict;
use warnings;

my $app = sub {
my $now = localtime;

return [
200,
[ 'Content-type' => 'text/plain' ],
[ "The time is $now" ]
];
};
22 changes: 22 additions & 0 deletions psgi3.cgi
@@ -0,0 +1,22 @@
#!/usr/bin/plackup

use strict;
use warnings;

my $app = sub {
my $now = localtime;

return [
200,
[ 'Content-type' => 'text/html' ],
[ "<html>
<head>
<title>Time</title>
</head>
<body>
<h1>Time</h1>
<p>The time is $now</p>
</body>
</html>" ] ];
};

26 changes: 26 additions & 0 deletions psgi4.cgi
@@ -0,0 +1,26 @@
#!/usr/bin/plackup

use strict;
use warnings;

use HTML::Tiny;

my $app = sub {
my $now = localtime;
my $title = 'Time';
my $h = HTML::Tiny->new;
my $body = $h->html([
$h->head( $h->title($title) ),
$h->body([
$h->h1($title),
$h->p("The time is $now"),
]),
]);

return [
200,
[ 'Content-type' => 'text/html' ],
[ $body ],
];
};

51 changes: 51 additions & 0 deletions psgi5.cgi
@@ -0,0 +1,51 @@
#!/usr/bin/plackup

use strict;
use warnings;

use Plack::Request;
use HTML::Tiny;

my $app = sub {
my $req = Plack::Request->new(shift);

my $name = $req->parameters->{name};
my $age = $req->parameters->{age};
my $gender = $req->parameters->{gender};
my @hobbies = $req->parameters->get_all('hobby');

my $list;

if (@hobbies) {
$list = join ', ', @hobbies;
} else {
$list = 'None';
}

my $h = HTML::Tiny->new;
my $body = $h->html([
$h->head($h->title($name)),
$h->body([
$h->h1("Welcome $name"),
$h->p('Here are your details:'),
$h->table([
$h->tr([
$h->td('Name:'),
$h->td($name),
], [
$h->td('Age:'),
$h->td($age),
], [
$h->td('Gender:'),
$h->td($gender),
], [
$h->td('Hobbies:'),
$h->td($list),
]),
]),
]),
]);

return [ 200, [ 'Content-type' => 'text/html' ], [ $body ] ];
};

0 comments on commit a87ddee

Please sign in to comment.