Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1293 dpurdie 1
###############################################################################
2
# Codestriker: Copyright (c) 2001, 2002 David Sitsky.  All rights reserved.
3
# sits@users.sourceforge.net
4
#
5
# This program is free software; you can redistribute it and modify it under
6
# the terms of the GPL.
7
 
8
# Collection of routines for maintaining HTTP cookies.
9
 
10
package Codestriker::Http::Cookie;
11
 
12
use strict;
13
 
14
use CGI::Carp 'fatalsToBrowser';
15
 
16
# Prototypes.
17
sub make( $$$ );
18
sub get( $$ );
19
sub get_property( $$$ );
20
 
21
# Cookie attribute to set.
22
my $COOKIE_NAME = "codestriker_cookie";
23
 
24
# Given a reference to a hash, create a cookie value that can be put into the
25
# HTTP response header.
26
sub make($$$) {
27
    my ($type, $query, $cookie_value_hash_ref) = @_;
28
 
29
    my $cookie_path = $query->url(-absolute=>1);
30
 
31
    return $query->cookie(-name=>"$COOKIE_NAME",
32
			  -expires=>'+10y',
33
			  -path=>"$cookie_path",
34
			  -value=>$cookie_value_hash_ref);
35
}
36
 
37
# Return the cookie value associated with this HTTP request.
38
sub get($$) {
39
    my ($type, $query) = @_;
40
 
41
    return $query->cookie($COOKIE_NAME);
42
}
43
 
44
# Return the cookie value associated with this HTTP request.
45
sub get_property($$$) {
46
    my ($type, $query, $property) = @_;
47
 
48
    if (defined $query->cookie($COOKIE_NAME)) {
49
	my %cookie = $query->cookie($COOKIE_NAME);
50
	return (defined $cookie{$property} ? $cookie{$property} : "");
51
    } else {
52
	return "";
53
    }
54
}