File Coverage

blib/lib/Apache/Usertrack.pm
Criterion Covered Total %
statement 4 6 66.6
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 6 8 75.0


line stmt bran cond sub pod time code
1             package Apache::Usertrack;
2 1     1   657 use strict;
  1         1  
  1         35  
3 1     1   1355 use Apache::Constants;
  0            
  0            
4             use Time::HiRes;
5             use integer;
6              
7             $Apache::Usertrack::revision = sprintf("%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/o);
8             $Apache::Usertrack::VERSION = '0.03';
9              
10             sub make_cookie {
11             my $r = shift;
12             my $remotename = $r->connection->remote_host || $r->connection->remote_ip;
13             my ($secs, $msecs) = Time::HiRes::gettimeofday;
14             $msecs /= 1000;
15             my $cookie = "Apache=$remotename.$$"."$secs$msecs; path=/";
16             $r->notes("cookie", $cookie);
17             $r->err_headers_out->add("Set-Cookie" => $cookie);
18             return OK;
19             }
20            
21             sub handler {
22             my $r = shift;
23             return DECLINED unless ($r->dir_config('Usertrack'));
24             if (my $cookies = $r->header_in("Cookie")) {
25             if (my $cookie = ($cookies =~ m/Apache=([^\s;]+)/)[0]) {
26             $r->notes("cookie", $cookie);
27             return DECLINED; # Theres already a cookie, no new one
28             }
29             }
30             return make_cookie($r);
31             }
32              
33             1;
34              
35             __END__