| 1 | package CGI::Session::Driver::aggregator::Drivers; | ||
| 2 | |||
| 3 | # $Id$ | ||
| 4 | |||
| 5 | =head1 NAME | ||
| 6 | |||
| 7 | CGI::Session::Driver::aggregator::Drivers - Drivers container for CGI::Session::Driver::aggregator | ||
| 8 | |||
| 9 | =cut | ||
| 10 | |||
| 11 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | 2 | ▶ | use Carp qw(croak); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | |||
| 14 | 0 | ▶ | sub new { bless { drivers => [] }, shift } |
|
Subroutine
new: not called CC=1 SCAR=6.9
| |||
| 15 | |||
| 16 | =head1 METHODS | ||
| 17 | |||
| 18 | =cut | ||
| 19 | |||
| 20 | =head2 add($driver_name, $driver_arguments) | ||
| 21 | |||
| 22 | Adding a driver with extra arguments. driver_arguments will be used to instanctiate the driver. The driver must be an instance of CGI::Session::Driver. | ||
| 23 | |||
| 24 | $drivers = CGI::Session::Driver::aggregator::Drivers->new; | ||
| 25 | $drivers->add('file', { Directory => '/tmp' }); | ||
| 26 | $drivers->add('mysql', { Handle => $dbh }); | ||
| 27 | |||
| 28 | NOTE: session data is read from drivers in the added order. In above example, reading from 'file' first, and then from 'mysql' (only when cannot read from 'file'). On the other hand, When writing session data, the order is 'mysql' -> 'file'. | ||
| 29 | |||
| 30 | =cut | ||
| 31 | sub add { | ||
| 32 | my ($self, $name, $args) = @_; | ||
| 33 | $name = lc $name; | ||
| 34 | |||
| 35 | my $package = "CGI::Session::Driver::$name"; | ||
| 36 | if (!defined defined ${"${name}::VERSION"} || !defined @{"${name}::ISA"}) { | ||
| 37 | eval "require $package"; | ||
| 38 | if ($@) { | ||
| 39 | croak "Failed to load a driver: $@"; | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | push @{ $self->{drivers} }, { package => $package, args => $args }; | ||
| 44 | } | ||
| 45 | |||
| 46 | sub drivers { @{ shift->{drivers} } } | ||
| 47 | |||
| 48 | 1; | ||