blib/lib/Siesta/Web.pm

filter: Statementstmt 86.6% 13 / 15 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 90.0% 18 / 20 CC 1 SCAR 0.6
CC
1
Cov
87%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« blib/lib/Siesta/Plugin/MessageFooter.pm ↑ Summary blib/lib/Template/Plugin/Siesta.pm »
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Siesta::Web;
3 1 ▶use Apache::Constants qw( :common );
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Apache::Session::SharedMem;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 0 ▶use CGI;
Subroutine BEGIN: called CC=1 SCAR=2.6
7 use Siesta;
8 use Siesta::Config;
9  
10 use constant Cookie => 'siesta_session';
11  
12 =head1 SYNOPSIS
13  
14 PerlModule Siesta::Web
15 <Files *.tt2>
16 SetHandler perl-script
17 PerlHandler Siesta::Web
18 </Files>
19  
20 =cut
21  
22 my $tt;
23 sub handler {
24 my $r = shift;
25  
26 my $file = $r->filename;
27 $file =~ /\.tt2$/ or return DECLINED;
28  
29 my $cgi = CGI->new;
30 my $session_id = $cgi->cookie( Cookie );
31 my %session;
32 # try the session in the cookie, or a new one
33 for my $id ($session_id, undef) {
34 eval {
35 tie %session, 'Apache::Session::SharedMem', $id,
36 +{ expires_in => 24 * 60 * 60 }; # 24 hours
37 };
38 last unless $@;
39 }
40  
41 unless ( $session{_session_id} ) {
42 $r->log_reason( "couldn't get session" );
43 return SERVER_ERROR;
44 }
45  
46 my @headers = (
47 [ 'Set-Cookie' =>
48 $cgi->cookie(-name => Cookie,
49 -value => $session{_session_id}) ]
50 );
51  
52 my $params = {
53 set_header => sub { push @headers, @_; return },
54 uri => $r->uri,
55 cgi => $cgi,
56 session => \%session,
57 };
58  
59 my $root = $Siesta::Config::config->root;
60 $tt ||= Template->new(
61 ABSOLUTE => 1,
62 INCLUDE_PATH => "$root/web-frontend/siesta:$root/web-frontend/lib" );
63  
64 my $out;
65 $tt->process($file, $params, \$out)
66 or do {
67 $r->log_reason( $tt->error );
68 return SERVER_ERROR;
69 };
70  
71 $r->header_out( @$_ ) for @headers;
72 $r->content_type('text/html');
73 $r->send_http_header;
74 $r->print( $out );
75  
76 return OK;
77 }
78  
79 1;
« blib/lib/Siesta/Plugin/MessageFooter.pm ↑ Summary blib/lib/Template/Plugin/Siesta.pm »