1############################################################################# 2# 3# Apache::Session::Flex 4# Apache persistent user sessions stored however you want 5# Copyright(c) 2000, 2001 Jeffrey William Baker (jwbaker@acm.org) 6# Distribute under the Perl License 7# 8############################################################################ 9 10package Apache::Session::Flex; 11 12use strict; 13use vars qw(@ISA $VERSION); 14 15$VERSION = '1.01'; 16@ISA = qw(Apache::Session); 17 18use Apache::Session; 19 20sub populate { 21 my $self = shift; 22 23 my $store = "Apache::Session::Store::$self->{args}->{Store}"; 24 my $lock = "Apache::Session::Lock::$self->{args}->{Lock}"; 25 my $gen = "Apache::Session::Generate::$self->{args}->{Generate}"; 26 my $ser = "Apache::Session::Serialize::$self->{args}->{Serialize}"; 27 28 for my $class ($store, $lock) { 29 unless ($class->can('new')) { 30 eval "require $class" || die $@; 31 } 32 } 33 34 unless ($gen->can('validate')) { 35 eval "require $gen" || die $@; 36 } 37 38 unless ($ser->can('serialize')) { 39 eval "require $ser" || die $@; 40 } 41 42 $self->{object_store} = new $store $self; 43 $self->{lock_manager} = new $lock $self; 44 { 45 no strict 'refs'; 46 $self->{generate} = \&{$gen . '::generate'}; 47 $self->{validate} = \&{$gen . '::validate'}; 48 $self->{serialize} = \&{$ser . '::serialize'}; 49 $self->{unserialize} = \&{$ser . '::unserialize'}; 50 } 51 52 return $self; 53} 54 551; 56 57=pod 58 59=head1 NAME 60 61Apache::Session::Flex - Specify everything at runtime 62 63=head1 SYNOPSIS 64 65 use Apache::Session::Flex; 66 67 tie %hash, 'Apache::Session::Flex', $id, { 68 Store => 'DB_File', 69 Lock => 'Null', 70 Generate => 'MD5', 71 Serialize => 'Storable' 72 }; 73 74 # or 75 76 tie %hash, 'Apache::Session::Flex', $id, { 77 Store => 'Postgres', 78 Lock => 'Null', 79 Generate => 'MD5', 80 Serialize => 'Base64' 81 }; 82 83 # you decide! 84 85=head1 DESCRIPTION 86 87This module is an implementation of Apache::Session. Unlike other 88implementations, it allows you to specify the backing store, locking scheme, 89ID generator, and data serializer at runtime. You do this by passing 90arguments in the usual Apache::Session style (see SYNOPSIS). You may 91use any of the modules included in this distribution, or a module of your 92own making. If you wish to use a module of your own making, you should 93make sure that it is available under the Apache::Session package namespace. 94 95=head1 USAGE 96 97You pass the modules you want to use as arguments to the constructor. The 98Apache::Session::Whatever part is appended for you: you should not supply it. 99For example, if you wanted to use MySQL as the backing store, you should give 100the argument C<Store => 'MySQL'>, and not 101C<Store => 'Apache::Session::Store::MySQL'>. There are four modules that you 102need to specify. Store is the backing store to use. Lock is the locking scheme. 103Generate is the ID generation module. Serialize is the data serialization 104module. 105 106There are many modules included in this distribution. For each role, they are: 107 108 Store: 109 MySQL 110 Postgres 111 DB_File 112 File 113 114 Lock: 115 Null 116 MySQL 117 Semaphore 118 119 Generate: 120 MD5 121 122 Serialize: 123 Storable 124 Base64 125 UUEncode 126 127In addition to the arguments needed by this module, you must provide whatever 128arguments are expected by the backing store and lock manager that you are 129using. Please see the documentation for those modules. 130 131=head1 AUTHOR 132 133This module was written by Jeffrey William Baker <jwbaker@acm.org>. 134 135=head1 SEE ALSO 136 137L<Apache::Session::File>, L<Apache::Session::DB_File>, 138L<Apache::Session::MySQL>, L<Apache::Session::Postgres>, L<Apache::Session> 139