diff --git a/cgi1.cgi b/cgi1.cgi new file mode 100755 index 0000000..e1b26bf --- /dev/null +++ b/cgi1.cgi @@ -0,0 +1,7 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +print "Content-type: text/plain\n\n"; +print 'Hello world'; diff --git a/cgi2.cgi b/cgi2.cgi new file mode 100755 index 0000000..50810fd --- /dev/null +++ b/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"; diff --git a/cgi3.cgi b/cgi3.cgi new file mode 100755 index 0000000..cdceb04 --- /dev/null +++ b/cgi3.cgi @@ -0,0 +1,19 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +print "Content-type: text/html\n\n"; +my $now = localtime; + +print < + + Time + + +

Time

+

The time is $now

+ + +END_HTML diff --git a/cgi4.cgi b/cgi4.cgi new file mode 100755 index 0000000..6c623d6 --- /dev/null +++ b/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; diff --git a/cgi5.cgi b/cgi5.cgi new file mode 100755 index 0000000..237d3e9 --- /dev/null +++ b/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; diff --git a/psgi1.cgi b/psgi1.cgi new file mode 100755 index 0000000..60fb6a6 --- /dev/null +++ b/psgi1.cgi @@ -0,0 +1,8 @@ +#!/usr/bin/plackup + +use strict; +use warnings; + +my $app = sub { + return [ 200, [ 'Content-type' => 'text/plain' ], [ 'Hello world' ] ]; +}; diff --git a/psgi2.cgi b/psgi2.cgi new file mode 100755 index 0000000..7e3c126 --- /dev/null +++ b/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" ] + ]; +}; diff --git a/psgi3.cgi b/psgi3.cgi new file mode 100755 index 0000000..3f4b981 --- /dev/null +++ b/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' ], + [ " + + Time + + +

Time

+

The time is $now

+ +" ] ]; +}; + diff --git a/psgi4.cgi b/psgi4.cgi new file mode 100755 index 0000000..aa7b0f7 --- /dev/null +++ b/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 ], + ]; +}; + diff --git a/psgi5.cgi b/psgi5.cgi new file mode 100755 index 0000000..235cc54 --- /dev/null +++ b/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 ] ]; +}; +