OpenInteract::Cookies::Apache - handler to parse/output cookies from/to the client using Apache::Cookie


OpenInteract documentation Contained in the OpenInteract distribution.

Index


Code Index:

NAME

Top

OpenInteract::Cookies::Apache - handler to parse/output cookies from/to the client using Apache::Cookie

SYNOPSIS

Top

 # In your website's 'conf/server.perl' file:

 # Use Apache::Cookie (from Apache::Request)

 'system_alias' => {
       cookies => 'OpenInteract::Cookies::Apache', ...
 }

 # Retrieve the cookies from the client request

 $R->cookies->parse;

 # Place cookies in the outbound content header

 $R->cookies->bake;

 # Retrieve a cookie value in an OpenInteract content handler

 $params->{search} = $R->{cookie}{in}{search_value};

 # Create a new cookie

 $R->cookies->create_cookie({ name    => 'search_value',
                              expires => '+3M',
                              value   => 'this AND that' });

 # Expire an old cookie

 $R->cookies->create_cookie({ name    => 'search_value',
                              expires => '-3d',
                              value   => undef });

DESCRIPTION

Top

This module defines methods for retrieving, setting and creating cookies. If you do not know what a cookie is, check out:

 http://www.ics.uci.edu/pub/ietf/http/rfc2109.txt

OpenInteract currently uses one of two modules to perform these actions. They adhere to the same interface but perform the actions using different helper modules. This module uses Apache::Cookie to do the actual cookie actions.

Note that Apache::Cookie does not work on all platforms, particularly Win32 (as of this writing). If Apache::Cookie does not work for you, please use the OpenInteract::Cookies::CGI module instead.

To use this implementation, set the following key in the conf/server.perl file for your website:

 system_aliases => {
   cookies => 'OpenInteract::Cookies::Apache', ...
 },

METHODS

Top

Methods for this class.

create_cookie( \%params )

This function is probably the only one you will ever use from this module. Pass in normal parameters (see below) and the function will create a cookie and put it into $R for you.

Parameters:

parse()

Read in the cookies passed to this request and file them into the hashref:

 $R->{cookie}{in}

with the key as the cookie name.

bake()

Puts the cookies from $R->{cookie}->{out} into the outgoing headers.

TO DO

Top

Nothing.

BUGS

Top

None known.

SEE ALSO

Top

Apache::Cookie

COPYRIGHT

Top

AUTHORS

Top

Chris Winters <chris@cwinters.com>


OpenInteract documentation Contained in the OpenInteract distribution.

package OpenInteract::Cookies::Apache;

# $Id: Apache.pm,v 1.5 2002/01/02 02:43:53 lachoy Exp $

use strict;
use Apache::Cookie;
use Data::Dumper qw( Dumper );

@OpenInteract::Cookies::Apache::ISA     = ();
$OpenInteract::Cookies::Apache::VERSION = sprintf("%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/);


# Retrieve the cookies using Apache::Request

sub parse {
    my ( $class ) = @_;
    my $R = OpenInteract::Request->instance;
    my $cookie_info = Apache::Cookie->fetch;
    foreach my $name ( keys %{ $cookie_info } ) {
        my $value = $cookie_info->{ $name }->value;
        $R->DEBUG && $R->scrib( 2, "Getting cookie $name to $value" );
        $R->{cookie}{in}{ $name } = $value;
    }
    return $R->{cookie}{in};
}


# Cycle through the Apache::Cookie objects and 
# call the bake method, which puts the appropriate header
# into the outgoing headers table.

sub bake {
    my ( $class ) = @_;
    my $R = OpenInteract::Request->instance;
    foreach my $name ( keys %{ $R->{cookie}{out} } ) {
        $R->DEBUG && $R->scrib( 2, "Setting $name to value ", $R->{cookie}{out}{ $name }->value );
        $R->{cookie}{out}{ $name }->bake;
    }
    return 1;
}


# Create a new cookie

sub create_cookie {
    my ( $class, $p ) = @_;
    my $R = OpenInteract::Request->instance;
    return $R->{cookie}{out}{ $p->{name} } = 
                    Apache::Cookie->new( $R->apache, 
                                         -name => $p->{name}, 
                                         -value => $p->{value},
                                         -path => $p->{path}, 
                                         -expires => $p->{expires} );
}

1;

__END__