Apache-Session-Browseable
view release on metacpan or search on metacpan
lib/Apache/Session/Browseable/MySQL.pm view on Meta::CPAN
package Apache::Session::Browseable::MySQL;
use strict;
use Apache::Session;
use Apache::Session::Lock::Null;
use Apache::Session::Browseable::Store::MySQL;
use Apache::Session::Generate::SHA256;
use Apache::Session::Serialize::JSON;
use Apache::Session::Browseable::DBI;
our $VERSION = '1.2.5';
our @ISA = qw(Apache::Session::Browseable::DBI Apache::Session);
sub populate {
my $self = shift;
$self->{object_store} = new Apache::Session::Browseable::Store::MySQL $self;
$self->{lock_manager} = new Apache::Session::Lock::Null $self;
$self->{generate} = \&Apache::Session::Generate::SHA256::generate;
$self->{validate} = \&Apache::Session::Generate::SHA256::validate;
$self->{serialize} = \&Apache::Session::Serialize::JSON::serialize;
$self->{unserialize} = \&Apache::Session::Serialize::JSON::unserialize;
return $self;
}
# Override default CAST syntax from DBI.pm
sub _buildLowerThanExpression {
my ( $class, $field, $value ) = @_;
return "CAST($field AS SIGNED INTEGER) < $value";
}
1;
__END__
=head1 NAME
Apache::Session::Browseable::MySQL - Add index and search methods to
Apache::Session::MySQL
=head1 SYNOPSIS
Create table with columns for indexed fields. Example for Lemonldap::NG:
CREATE TABLE sessions (
id varchar(64) not null primary key,
a_session text,
_whatToTrace text,
_session_kind text,
_utime bigint,
ipAddr text
);
Add indexes:
CREATE INDEX uid1 ON sessions (_whatToTrace) USING BTREE;
CREATE INDEX s1 ON sessions (_session_kind);
CREATE INDEX u1 ON sessions (_utime);
CREATE INDEX ip1 ON sessions (ipAddr) USING BTREE;
Use it with Perl:
use Apache::Session::Browseable::MySQL;
my $args = {
DataSource => 'dbi:mysql:sessions',
UserName => $db_user,
Password => $db_pass,
LockDataSource => 'dbi:mysql:sessions',
LockUserName => $db_user,
LockPassword => $db_pass,
# Choose your browseable fileds
Index => 'uid mail',
};
# Use it like Apache::Session
my %session;
tie %session, 'Apache::Session::Browseable::MySQL', $id, $args;
$session{uid} = 'me';
( run in 1.024 second using v1.01-cache-2.11-cpan-39bf76dae61 )