| 1 | package CGI::Session::Driver::aggregator; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | # $Id$ | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use CGI::Session::Driver; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | @CGI::Session::Driver::aggregator::ISA = ( "CGI::Session::Driver" ); | |||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | $CGI::Session::Driver::aggregator::VERSION = "0.04"; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 17 | ▶ | sub drivers { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
drivers: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 17 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 14 | 17 | return @{ $self->{drivers} }; | |||||||||||||||||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 8 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 8 | ▶ | unless (defined $self->{Drivers}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | return $self->set_error("init(): 'Drivers' attribute is required."); | |||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 8 | my @drivers; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 8 | ▶ | $self->{drivers} ||= []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"drivers"} ||= []
MC/DC0%0/1
$self->{"drivers"} ||= []
$self->{"drivers"}
Truth table50%1/2
A
A= $self->{"drivers"}
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 8 | for my $d ( $self->{Drivers}->drivers ) { | |||||||||||||||||||||||||||||||||||||||||
| 26 | 16 | my $obj = $d->{package}->new($d->{args}); | |||||||||||||||||||||||||||||||||||||||||
| 27 | 16 | push @drivers, $obj; | |||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 8 | $self->{drivers} = \@drivers; | |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 8 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 7 | ▶ | sub retrieve { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
retrieve: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 7 | my ($sid) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 7 | ▶ | croak "retrieve(): usage error" unless $sid; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 7 | for my $driver ($self->drivers) { | |||||||||||||||||||||||||||||||||||||||||
| 41 | 10 | ▶ | if (my $data = $driver->retrieve(@_)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 4 | return $data; | |||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 6 | ▶ | sub store { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
store: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 6 | my ($sid, $datastr) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 6 | ▶ | croak "store(): usage error" unless $sid && $datastr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$sid and $datastr
MC/DC0%0/2
$sid and $datastr
$sid
$datastr
Truth table33%1/3
A and B
A= $sidB= $datastr
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 6 | for my $driver (reverse $self->drivers) { | |||||||||||||||||||||||||||||||||||||||||
| 55 | 12 | $driver->store(@_); | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 6 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 4 | ▶ | sub remove { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remove: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 4 | my ($sid) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 4 | ▶ | croak "remove(): usage error" unless $sid; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 4 | for my $driver (reverse $self->drivers) { | |||||||||||||||||||||||||||||||||||||||||
| 67 | 8 | $driver->remove(@_); | |||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 4 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 8 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | sub traverse { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
traverse: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | my ($coderef) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | unless ( $coderef && ref( $coderef ) && (ref $coderef eq 'CODE') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$coderef and ref $coderef and ref $coderef eq "CODE"
$coderef and ref $coderef
MC/DC0%0/3
$coderef and ref $coderef and ref $coderef eq "CODE"
$coderef
ref $coderef
ref $coderef eq "CODE"
Truth table0%0/4
A and B and C
A= $coderefB= ref $coderefC= ref $coderef eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | croak "traverse(): usage error"; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | for my $driver ($self->drivers) { | |||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | $driver->traverse(@_); | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | CGI::Session::Driver::aggregator - CGI::Session driver to aggregate some CGI::Session drivers. | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | use CGI::Session; | ||||||||||||||||||||||||||||||||||||||||||
| 105 | use CGI::Session::Driver::aggregator::Drivers; | ||||||||||||||||||||||||||||||||||||||||||
| 106 | use DBI; | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | $dbh = DBI->connect('DBI:mysql:cgi_session;host=localhost', 'root', ''); | ||||||||||||||||||||||||||||||||||||||||||
| 109 | $drivers = CGI::Session::Driver::aggregator::Drivers->new; | ||||||||||||||||||||||||||||||||||||||||||
| 110 | $drivers->add('file', { Directory => '/tmp' }); | ||||||||||||||||||||||||||||||||||||||||||
| 111 | $drivers->add('mysql', { Handle => $dbh }); | ||||||||||||||||||||||||||||||||||||||||||
| 112 | $s = CGI::Session->new('driver:aggregator', $sid, { Drivers => $drivers }); | ||||||||||||||||||||||||||||||||||||||||||
| 113 | $s->param(hey => 'Blur blur blur!'); | ||||||||||||||||||||||||||||||||||||||||||
| 114 | # ----> Store datas into mysql and file!! | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | $value = $s->param('hey'); | ||||||||||||||||||||||||||||||||||||||||||
| 117 | # ----> Read datas from file (When cannot find, then from mysql) | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | B<aggregator> stores session data into anything to be set up. | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | =head1 DRIVER ARGUMENTS | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | The only supported driver argument is 'Drivers'. It's an instance of L<CGI::Session::Driver::aggregator::Drivers|CGI::Session::Driver::aggregator::Drivers>. | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | =head1 REQUIREMENTS | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | =item L<CGI::Session> | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | Kazuhiro Oinuma <oinume@cpan.org> | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | Copyright (C) 2005 - 2006 Kazuhiro Oinuma <oinume@cpan.org>. All rights reserved. This library is free software. You can modify and or distribute it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||