/usr/share/doc/libplack-middleware-session-perl/examples/counter-raw.psgi is in libplack-middleware-session-perl 0.21-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | #!/usr/bin/perl
# Simple counter web application
# NOTE: This example uses Plack::Request to illustrate how
# Plack::Middleware::Session interface ($env->{'psgix.session'}) could
# be wrapped and integrated as part of the request API. See Tatsumaki
# (integrated via subclassing Plack::Request) and Dancer::Session::PSGI
# how to adapt Plack::Middleware::Session to web frameworks' APIs.
# You're not recommended to write a new web application using this style.
use strict;
use Plack::Session;
use Plack::Session::State;
use Plack::Session::State::Cookie;
use Plack::Session::Store;
use Plack::Middleware::Session;
my $app = Plack::Middleware::Session->wrap(
sub {
my $env = shift;
my $r = Plack::Request->new( $env );
return [ 404, [], [] ] if $r->path_info =~ /favicon.ico/;
my $session = $r->session;
my $id = $session->id;
my $counter = $session->get('counter') || 0;
$session->set( 'counter' => $counter + 1 );
my $resp;
if ( $r->param( 'logout' ) ) {
$session->expire;
$resp = $r->new_response;
$resp->redirect( $r->path_info );
}
else {
$resp = $r->new_response(
200,
[ 'Content-Type' => 'text/html' ],
[
qq{
<html>
<head>
<title>Plack::Middleware::Session Example</title>
</head>
<body>
<h1>Session Id: ${id}</h1>
<h2>Counter: ${counter}</h2>
<hr/>
<a href="/?logout=1">Logout</a>
</body>
</html>
}
]
);
}
$resp->finalize;
},
state => Plack::Session::State::Cookie->new,
store => Plack::Session::Store->new,
);
|