| 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 | |||||||||||
| 10 | package Apache::Session::Flex; | ||||||||||
| 11 | |||||||||||
| 12 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 1 | ▶ | use vars qw(@ISA $VERSION); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 1 | $VERSION = '1.01'; | |||||||||
| 16 | 1 | @ISA = qw(Apache::Session); | |||||||||
| 17 | |||||||||||
| 18 | 1 | ▶ | use Apache::Session; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | |||||||||||
| 20 | 2 | ▶ | sub populate { | ||||||||
|
Subroutine
populate: called CC=8 SCAR=21.1
Pod
undocumented
| |||||||||||
| 21 | 2 | my $self = shift; | |||||||||
| 22 | |||||||||||
| 23 | 2 | my $store = "Apache::Session::Store::$self->{args}->{Store}"; | |||||||||
| 24 | 2 | my $lock = "Apache::Session::Lock::$self->{args}->{Lock}"; | |||||||||
| 25 | 2 | my $gen = "Apache::Session::Generate::$self->{args}->{Generate}"; | |||||||||
| 26 | 2 | my $ser = "Apache::Session::Serialize::$self->{args}->{Serialize}"; | |||||||||
| 27 | |||||||||||
| 28 | 2 | for my $class ($store, $lock) { | |||||||||
| 29 | 4 | ▶ | unless ($class->can('new')) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 0 | ▶ | eval "require $class" || die $@; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | } | ||||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 2 | ▶ | unless ($gen->can('validate')) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 1 | ▶ | eval "require $gen" || die $@; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | 2 | ▶ | unless ($ser->can('serialize')) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 1 | ▶ | eval "require $ser" || die $@; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 2 | $self->{object_store} = new $store $self; | |||||||||
| 43 | 2 | $self->{lock_manager} = new $lock $self; | |||||||||
| 44 | { | ||||||||||
| 45 | 1 | ▶ | no strict 'refs'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 46 | 2 | $self->{generate} = \&{$gen . '::generate'}; | |||||||||
| 47 | 2 | $self->{validate} = \&{$gen . '::validate'}; | |||||||||
| 48 | 2 | $self->{serialize} = \&{$ser . '::serialize'}; | |||||||||
| 49 | 2 | $self->{unserialize} = \&{$ser . '::unserialize'}; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 2 | return $self; | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 1 | 1; | |||||||||
| 56 | |||||||||||
| 57 | =pod | ||||||||||
| 58 | |||||||||||
| 59 | =head1 NAME | ||||||||||
| 60 | |||||||||||
| 61 | Apache::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 | |||||||||||
| 87 | This module is an implementation of Apache::Session. Unlike other | ||||||||||
| 88 | implementations, it allows you to specify the backing store, locking scheme, | ||||||||||
| 89 | ID generator, and data serializer at runtime. You do this by passing | ||||||||||
| 90 | arguments in the usual Apache::Session style (see SYNOPSIS). You may | ||||||||||
| 91 | use any of the modules included in this distribution, or a module of your | ||||||||||
| 92 | own making. If you wish to use a module of your own making, you should | ||||||||||
| 93 | make sure that it is available under the Apache::Session package namespace. | ||||||||||
| 94 | |||||||||||
| 95 | =head1 USAGE | ||||||||||
| 96 | |||||||||||
| 97 | You pass the modules you want to use as arguments to the constructor. The | ||||||||||
| 98 | Apache::Session::Whatever part is appended for you: you should not supply it. | ||||||||||
| 99 | For example, if you wanted to use MySQL as the backing store, you should give | ||||||||||
| 100 | the argument C<Store => 'MySQL'>, and not | ||||||||||
| 101 | C<Store => 'Apache::Session::Store::MySQL'>. There are four modules that you | ||||||||||
| 102 | need to specify. Store is the backing store to use. Lock is the locking scheme. | ||||||||||
| 103 | Generate is the ID generation module. Serialize is the data serialization | ||||||||||
| 104 | module. | ||||||||||
| 105 | |||||||||||
| 106 | There 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 | |||||||||||
| 127 | In addition to the arguments needed by this module, you must provide whatever | ||||||||||
| 128 | arguments are expected by the backing store and lock manager that you are | ||||||||||
| 129 | using. Please see the documentation for those modules. | ||||||||||
| 130 | |||||||||||
| 131 | =head1 AUTHOR | ||||||||||
| 132 | |||||||||||
| 133 | This module was written by Jeffrey William Baker <jwbaker@acm.org>. | ||||||||||
| 134 | |||||||||||
| 135 | =head1 SEE ALSO | ||||||||||
| 136 | |||||||||||
| 137 | L<Apache::Session::File>, L<Apache::Session::DB_File>, | ||||||||||
| 138 | L<Apache::Session::MySQL>, L<Apache::Session::Postgres>, L<Apache::Session> | ||||||||||