File Coverage

blib/lib/AxKit/App/TABOO.pm
Criterion Covered Total %
statement 13 15 86.6
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 18 20 90.0


line stmt bran cond sub pod time code
1             package AxKit::App::TABOO;
2              
3             our $VERSION = '0.52';
4              
5 1     1   8875 use 5.7.3;
  1         4  
  1         110  
6 1     1   6 use strict;
  1         3  
  1         36  
7 1     1   6 use warnings;
  1         7  
  1         39  
8              
9 1     1   889 use Session;
  1         4878  
  1         41  
10 1     1   2300 use Apache;
  0            
  0            
11             use Apache::Cookie;
12             use Apache::Request;
13             use AxKit;
14              
15             sub session_config {
16             my $r = shift;
17             my $prefix = $r->dir_config( 'TABOOPrefix') || 'TABOO';
18             my %session_config = (
19             Store => $r->dir_config( $prefix . 'DataStore' ) || 'DB_File',
20             Lock => $r->dir_config( $prefix . 'Lock' ) || 'Null',
21             Generate => $r->dir_config( $prefix . 'Generate' ) || 'MD5',
22             Serialize => $r->dir_config( $prefix . 'Serialize' ) || 'Storable'
23             );
24            
25             # When using Postgres, a different default is needed.
26             if ($session_config{'Store'} eq 'Postgres') {
27             $session_config{'Commit'} = 1;
28             $session_config{'Serialize'} = $r->dir_config( $prefix . 'Serialize' ) || 'Base64'
29             }
30              
31            
32             # Load session-type specific parameters, comma-separated, name => value pairs
33             foreach my $arg ( split( /\s*,\s*/, $r->dir_config($prefix . 'Args'))) {
34             my ($key, $value) = split( /\s*=>\s*/, $arg );
35             $session_config{$key} = $value;
36             }
37              
38             return %session_config;
39             }
40              
41             sub session {
42             my $r = shift;
43             my $req = Apache::Request->instance($r);
44             my $vid = $req->param('VID');
45             unless ($vid) { # Then look in the cookie
46             my $cookies = Apache::Cookie->fetch;
47             my $tmp = $cookies->{'VID'};
48             return undef unless defined($tmp);
49             $vid = $tmp->value;
50             return undef unless ($vid); # No session key
51             }
52             AxKit::Debug(9, "User's visitor ID: $vid");
53             return new Session $vid, session_config($r);
54             }
55            
56              
57             sub authlevel {
58             my $session = shift;
59             if (defined($session)) {
60             return $session->get('authlevel');
61             } else {
62             return 0;
63             }
64             }
65              
66             sub loggedin {
67             my $session = shift;
68             if (defined($session)) {
69             return $session->get('loggedin');
70             } else {
71             return 'guest';
72             }
73             }
74              
75             1;
76             __END__