Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Starting on code for article 3.
- Loading branch information
Showing
4 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/perl -T | ||
|
||
use strict; | ||
use warnings; | ||
use CGI ':standard'; | ||
|
||
my $info = path_info; | ||
|
||
print header, | ||
start_html, | ||
h1('Path Info'), | ||
p('Here are the contents of $ENV{PATH_INFO}'); | ||
|
||
my @info = split /\//, $info; | ||
|
||
print ul(li([@info])); | ||
|
||
print end_html; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/plackup | ||
|
||
use strict; | ||
use warnings; | ||
use Plack::Request; | ||
use HTML::Tiny; | ||
|
||
my $app = sub { | ||
my $info = Plack::Request->new(shift)->path_info; | ||
my @info = split /\//, $info; | ||
|
||
my $h = HTML::Tiny->new; | ||
my $body = $h->html( | ||
$h->body([ | ||
$h->h1('Path Info'), | ||
$h->p('Here are the contents of $ENV{PATH_INFO}'), | ||
$h->ul([ $h->li(@info) ]), | ||
]), | ||
); | ||
|
||
return [ 200, [ 'Content-type' => 'text/html' ], [ $body ] ]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/perl -T | ||
|
||
use strict; | ||
use warnings; | ||
use CGI ':standard'; | ||
|
||
my $time_cookie = cookie(-name=>'time', | ||
-value=>scalar localtime, | ||
-expires=>'+1y'); | ||
|
||
print header(-cookie => $time_cookie), | ||
start_html(-title=>'Cookie test'), | ||
h1('Cookie test'); | ||
|
||
if (my $time = cookie('time')) { | ||
print p("You last visited this page at $time"); | ||
} else { | ||
print p("You haven't visited this page before"); | ||
} | ||
|
||
print end_html; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/plackup | ||
|
||
use strict; | ||
use warnings; | ||
use Plack::Request; | ||
use Plack::Response; | ||
use HTML::Tiny; | ||
|
||
my $app = sub { | ||
my $time = Plack::Request->new(shift)->cookies->{time}; | ||
my $time_text; | ||
if ($time) { | ||
$time_text = "You last visited this page at $time"; | ||
} else { | ||
$time_text = "You haven't visited this page before"; | ||
} | ||
|
||
my $res = Plack::Response->new(200); | ||
$res->cookies->{time} = { | ||
value => scalar localtime, | ||
expires => '+1y', | ||
}; | ||
$res->content_type('text/html'); | ||
|
||
my $h = HTML::Tiny->new; | ||
my $body = $h->html([ | ||
$h->head( | ||
$h->title('Cookie Test'), | ||
), | ||
$h->body([ | ||
$h->h1('Cookie Test'), | ||
$h->p($time_text), | ||
]), | ||
]); | ||
|
||
$res->body($body); | ||
return $res->finalize; | ||
}; | ||
|