The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
CGI::LDAPSession::CookieJar::DBI

A DBI Based CookieJar.

The general usage is as follows:

my $cookiejar; $cookiejar = new CGI::LDAPSession::CookieJar::DBI(); $cookiejar->use_mysql(); $cookiejar->user( 'MyMYSQLUser' ); $cookiejar->password( 'lijlkdfsf' ); $cookiejar->database( 'DBI' ); $cookiejar->host( 'my.dbi.server.myco.com' ); $cookiejar->open(); ... ... cookie operations ... $cookiejar->close();

Most functions manipulating cookies use "queries" to specify the cookies which will be operated upon. These queries are references to associative arrays. The keys indicate variables which will be compared, and the values specify the query operations. These intersection of all the results determines which ones will be selected.

Here are examples of simple queries:

{ user => "bob" } selects all cookies with the user value of "bob"

{ expiration => "<".time() } selects all cookies which have already expired

{ expiration => ">".time() } selects all cookies which have not expired

{ cookie_name => "$cookie" } selects all cookies which are named $cookie

{ passkey => "435765" } selects all cookies which have the passkey value of "435765"

{ user => "bob", passkey => "6578" } selects all cookies which have the user "bob" and the passkey set to "6578"

There is no way to select a union of search results.

CGI::LDAPSession::CookieJar::DBI::open

$cookiejar->open();

Opens up the cookie jar. This must be called before any operations can take place. When you are through with the cookie jar the close operation me be called.

CGI::LDAPSession::CookieJar::DBI::close

$cookiejar->close;

Closes a previously opened cookie jar. This must be done before your program ends.

CGI::LDAPSession::CookieJar::DBI::contains

Determines if a session contains a given cookie.

my $time = time; my %query = ( -user=>'bob', -cookie=>'3476dfgh', -passkey=>'23438', -expiration=>'>$time' );

my $has_cookie = $cookie_jar->contains( -query => \$query );

CGI::LDAPSession::CookieJar::DBI::cookie

Retreives a cookie from the cookie jar using a specified query. If no cookie is found then it returns 'undef'.

By default all cookie fields are returned. If your application potentially contains large 'server_data' fields this may not be what you want. In these cases you can specify a list of fields to omit. These fields are passed in via array reference.

my $time = time; my %query = ( -user=>'bob', -cookie_name=>'3476dfgh', -passkey=>'23438', -expiration=>'>$time' );

my $sessions = $cookie_jar->session( -query => \%query );

if ( !defined $cookie ) { croak "There is no such cookie."; }

...or...

my $cookie = $cookie_jar->session( -query => \%query, -omit_server_side_data => 1 );

CGI::LDAPSession::CookieJar::DBI::delete

Deletes the specified cookies from the cookie jar.

my $time = time; my %query = ( expiration=>'<$time' ); $cookie_jar->delete( %query );

CGI::LDAPSession::CookieJar::DBI::set_session

Creates a new session

my $time = time; my %session = ( user=>'bob', cookie_name=>'3476dfgh', passkey=>'23438', expiration=>'$time', server_side_data=>$data );

my $cookie_jar->set_session( -session => \$cookie );

CGI::LDAPSession::CookieJar::DBI::register_user

Creates an entry for the specified user within the cookie table.

  if ( ! $self->contains( -user=>$username ) )
    {
      $self->register_user( $username );
    }
CGI::LDAPSession::CookieJar::DBI::version

Returns the version of CGI::LDAPSession that was used to create this data store.

my $version => $cookie_jar->version();

Creates a new cookie jar. For a database cookie jar this would create the necessary tables. For a file based cookie jar this might set up the required directory structure.

This should only be necessary once.

$cookie_jar->create_cookie_jar();

Destroys an existing cookie jar. For a database cookie jar this would drop all of the tables. For a file based cookie jar this might delete all the existing files and directories.

This should only be necessary once.

$cookie_jar->destroy_cookie_jar();

CGI::LDAPSession::CookieJar::DBI::error

If the previous cookie operation resulted in an error then the value of this error will be found here. If the operation did not result in an error then this will return 'undef'.

Calling error() does not alter the value. Each cookie jar object has it's own error state, which is independent of the backend database.

my $error = $cookie_jar->error();

CGI::LDAPSession::CookieJar::DBI::database

Accessor method. The name of the database.

Database tables

The names of the database tables.

CGI::LDAPSession::CookieJar::DBI::cookie_table

Accessor method. The name of the cookie table.

CGI::LDAPSession::CookieJar::DBI::user_column

Accessor method. The column containing the usernames.

CGI::LDAPSession::CookieJar::DBI::passkey_column

Accessor method. The column containing the passkey.

CGI::LDAPSession::CookieJar::DBI::cookie_column

Accessor method. The column containing the cookie id.

CGI::LDAPSession::CookieJar::DBI::login_expiration_column

Accessor method. The expiration time for the cookie. Currently not used, but it will be used in the future.

CGI::LDAPSession::CookieJar::DBI::server_side_data_column

Accessor method. The name of the column containing server side data.

  Creates the database tables that are described by a CGI::LDAPSession.

  my $session = new CGI::LDAPSession;
  $session->create_cookie_table;
  exit;

  Fill out your CGI::LDAPSession just like your going to make
  a connection.  Call this routine, and voila!  Your database
  tables are created.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 44:

'=item' outside of any '=over'

=over without closing =back