view release on metacpan or search on metacpan
lib/Apache/Session.pm view on Meta::CPAN
eval {
tie %global_data, 'Apache::Session::File', 1,
{Directory => '/tmp/sessiondata'};
};
if ($@) {
die "Global data is not accessible: $@";
}
my $dbh = DBI->connect($global_data{datasource},
$global_data{username}, $global_data{password}) || die $DBI::errstr;
undef %global_data;
#program continues...
As shown in this example, you should undef or untie your session hash
as soon as you are done with it. This will free up any locks associated
with your process.
=head2 Tracking users with cookies
lib/Apache/Session.pm view on Meta::CPAN
my $cookie = $r->header_in('Cookie');
$cookie =~ s/SESSION_ID=(\w*)/$1/;
#create a session object based on the cookie we got from the browser,
#or a new session if we got no cookie
my %session;
tie %session, 'Apache::Session::MySQL', $cookie, {
DataSource => 'dbi:mysql:sessions', #these arguments are
UserName => 'mySQL_user', #required when using
Password => 'password', #MySQL.pm
LockDataSource => 'dbi:mysql:sessions',
LockUserName => 'mySQL_user',
LockPassword => 'password'
};
#Might be a new session, so lets give them their cookie back
my $session_cookie = "SESSION_ID=$session{_session_id};";
$r->header_out("Set-Cookie" => $session_cookie);
#program continues...
=head1 SEE ALSO
lib/Apache/Session/Lock/MySQL.pm view on Meta::CPAN
Apache::Session::Lock::MySQL fulfills the locking interface of
Apache::Session. Mutual exclusion is achieved through the use of MySQL's
GET_LOCK and RELEASE_LOCK functions. MySQL does not support the notion
of read and write locks, so this module only supports exclusive locks. When
you request a shared read lock, it is instead promoted to an exclusive
write lock.
=head1 CONFIGURATION
The module must know how to connect to your MySQL database to acquire locks.
You must provide a datasource name, a user name, and a password. These options
are passed in the usual Apache::Session style, and are very similar to the
options for Apache::Session::Store::MySQL. Example:
tie %hash, 'Apache::Session::MySQL', $id, {
LockDataSource => 'dbi:mysql:database',
LockUserName => 'database_user',
LockPassword => 'K00l'
};
Instead, you may pass in an already opened DBI handle to your database.
lib/Apache/Session/Lock/Sybase.pm view on Meta::CPAN
Apache::Session. Mutual exclusion is achieved through the use of Sybase's
sp_getapplock and sp_releaseapplock functions. Sybase does not support the
notion
of read and write locks, so this module only supports exclusive locks. When
you request a shared read lock, it is instead promoted to an exclusive
write lock.
=head1 CONFIGURATION
The module must know how to connect to your MySQL database to acquire locks.
You must provide a datasource name, a user name, and a password. These options
are passed in the usual Apache::Session style, and are very similar to the
options for Apache::Session::Store::Sybase. Example:
tie %hash, 'Apache::Session::Sybase', $id, {
LockDataSource => 'dbi:sybase:database',
LockUserName => 'database_user',
LockPassword => 'K00l'
};
Instead, you may pass in an already opened DBI handle to your database.
lib/Apache/Session/Store/Informix.pm view on Meta::CPAN
if (exists $session->{args}->{Handle}) {
$self->{dbh} = $session->{args}->{Handle};
$self->{commit} = $session->{args}->{Commit};
return;
}
my $datasource = $session->{args}->{DataSource} ||
$Apache::Session::Store::Informix::DataSource;
my $username = $session->{args}->{UserName} ||
$Apache::Session::Store::Informix::UserName;
my $password = $session->{args}->{Password} ||
$Apache::Session::Store::Informix::Password;
$self->{dbh} = DBI->connect(
$datasource,
$username,
$password,
{ RaiseError => 1, AutoCommit => 0 }
) || die $DBI::errstr;
#If we open the connection, we close the connection
$self->{disconnect} = 1;
#the programmer has to tell us what commit policy to use
$self->{commit} = $session->{args}->{Commit};
}
lib/Apache/Session/Store/Informix.pm view on Meta::CPAN
CREATE TABLE sessions (
id char(32) not null primary key,
a_session lvarchar
);
If you use some other command, ensure that there is a unique index on the
table's id column.
=head1 CONFIGURATION
The module must know what datasource, username, and password to use when
connecting to the database. These values can be set using the options hash
(see Apache::Session documentation). The options are DataSource, UserName,
and Password.
Example:
tie %hash, 'Apache::Session::Informix', $id, {
DataSource => 'dbi:Informix:database',
UserName => 'database_user',
Password => 'K00l'
lib/Apache/Session/Store/MySQL.pm view on Meta::CPAN
if (exists $session->{args}->{Handle}) {
$self->{dbh} = $session->{args}->{Handle};
return;
}
my $datasource = $session->{args}->{DataSource} ||
$Apache::Session::Store::MySQL::DataSource;
my $username = $session->{args}->{UserName} ||
$Apache::Session::Store::MySQL::UserName;
my $password = $session->{args}->{Password} ||
$Apache::Session::Store::MySQL::Password;
$self->{dbh} = DBI->connect(
$datasource,
$username,
$password,
{ RaiseError => 1, AutoCommit => 1 }
) || die $DBI::errstr;
#If we open the connection, we close the connection
$self->{disconnect} = 1;
}
sub DESTROY {
my $self = shift;
lib/Apache/Session/Store/MySQL.pm view on Meta::CPAN
CREATE TABLE sessions (
id char(32) not null primary key,
a_session blob
);
If you use some other command, ensure that there is a unique index on the
table's id column.
=head1 CONFIGURATION
The module must know what datasource, username, and password to use when
connecting to the database. These values can be set using the options hash
(see Apache::Session documentation). The options are:
=over 4
=item DataSource
=item UserName
=item Password
lib/Apache/Session/Store/Oracle.pm view on Meta::CPAN
if (exists $session->{args}->{Handle}) {
$self->{dbh} = $session->{args}->{Handle};
$self->{commit} = $session->{args}->{Commit};
return;
}
my $datasource = $session->{args}->{DataSource} ||
$Apache::Session::Store::Oracle::DataSource;
my $username = $session->{args}->{UserName} ||
$Apache::Session::Store::Oracle::UserName;
my $password = $session->{args}->{Password} ||
$Apache::Session::Store::Oracle::Password;
$self->{dbh} = DBI->connect(
$datasource,
$username,
$password,
{ RaiseError => 1, AutoCommit => 0 }
) || die $DBI::errstr;
#If we open the connection, we close the connection
$self->{disconnect} = 1;
#the programmer has to tell us what commit policy to use
$self->{commit} = $session->{args}->{Commit};
}
lib/Apache/Session/Store/Oracle.pm view on Meta::CPAN
CREATE TABLE sessions (
id varchar2(32) not null primary key,
a_session long
);
If you use some other command, ensure that there is a unique index on the
table's id column.
=head1 CONFIGURATION
The module must know what datasource, username, and password to use when
connecting to the database. These values can be set using the options hash
(see Apache::Session documentation). The options are DataSource, UserName,
and Password.
Example:
tie %hash, 'Apache::Session::Oracle', $id, {
DataSource => 'dbi:Oracle:database',
UserName => 'database_user',
Password => 'K00l'
lib/Apache/Session/Store/Postgres.pm view on Meta::CPAN
if (exists $session->{args}->{Handle}) {
$self->{dbh} = $session->{args}->{Handle};
$self->{commit} = $session->{args}->{Commit};
return;
}
my $datasource = $session->{args}->{DataSource} ||
$Apache::Session::Store::Postgres::DataSource;
my $username = $session->{args}->{UserName} ||
$Apache::Session::Store::Postgres::UserName;
my $password = $session->{args}->{Password} ||
$Apache::Session::Store::Postgres::Password;
$self->{dbh} = DBI->connect(
$datasource,
$username,
$password,
{ RaiseError => 1, AutoCommit => 0 }
) || die $DBI::errstr;
#If we open the connection, we close the connection
$self->{disconnect} = 1;
#the programmer has to tell us what commit policy to use
$self->{commit} = $session->{args}->{Commit};
}
lib/Apache/Session/Store/Postgres.pm view on Meta::CPAN
CREATE TABLE sessions (
id char(32) not null primary key,
a_session text
);
If you use some other command, ensure that there is a unique index on the
table's id column.
=head1 CONFIGURATION
The module must know what datasource, username, and password to use when
connecting to the database. These values can be set using the options hash
(see Apache::Session documentation). The options are:
=over 4
=item DataSource
=item UserName
=item Password
lib/Apache/Session/Store/Sybase.pm view on Meta::CPAN
if ( exists $session->{args}->{Handle} ) {
$self->{dbh} = $session->{args}->{Handle};
$self->{commit} = $session->{args}->{Commit};
}
else {
my $datasource = $session->{args}->{DataSource} ||
$Apache::Session::Store::Sybase::DataSource;
my $username = $session->{args}->{UserName} ||
$Apache::Session::Store::Sybase::UserName;
my $password = $session->{args}->{Password} ||
$Apache::Session::Store::Sybase::Password;
$self->{dbh} = DBI->connect(
$datasource,
$username,
$password,
{ RaiseError => 1, AutoCommit => 0 }
) || die $DBI::errstr;
# If we open the connection, we close the connection
$self->{disconnect} = 1;
}
# the programmer has to tell us what commit policy to use;
# note that this should take effect even if the programmer
lib/Apache/Session/Store/Sybase.pm view on Meta::CPAN
id CHAR(32) not null primary key,
a_session TEXT
)
go
If you use some other command, ensure that there is a unique index on the
id column of the table
=head1 CONFIGURATION
The module must know what datasource, username, and password to use when
connecting to the database. These values can be set using the options hash
(see Apache::Session documentation). The options are:
=over 4
=item DataSource
=item UserName
=item Password
t/99mysql.t view on Meta::CPAN
}
my @db_handles = Test::Database->handles('mysql');
plan skip_all => "No mysql handle reported by Test::Database"
unless @db_handles;
my $mysql = $db_handles[0];
my $dsn = $mysql->dsn();
my $uname = $mysql->username();
my $upass = $mysql->password();
diag "DBD::mysql version ".DBD::mysql->VERSION();
plan skip_all => "Test::Database handle->driver is undef. Probably it was not possible to establish connection."
if !defined($mysql->driver);
diag "Mysql version ".$mysql->driver->version;
plan tests => 23;
my $package = 'Apache::Session::MySQL';
t/99mysqllock.t view on Meta::CPAN
}
my @db_handles = Test::Database->handles('mysql');
plan skip_all => "No mysql handle reported by Test::Database"
unless @db_handles;
my $mysql = $db_handles[0];
my $dsn = $mysql->dsn();
my $uname = $mysql->username();
my $upass = $mysql->password();
my $dbh = DBI->connect($dsn, $uname, $upass);
plan skip_all => "Cannot connect to DB specified in Test::Database config"
unless $dbh;
plan tests => 4;
my $package = 'Apache::Session::Lock::MySQL';
use_ok $package;