aggregator.pm untested

filter: Statementstmt 0.0% 0 / 52 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 11 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 92 SCAR 40.3
CC
7
Cov
0%
retrieve
12.0
init
6.0
store
6.0
CRAP 56.0
1 package CGI::Session::Driver::aggregator;
2  
3 # $Id$
4  
5 use strict;
6 use Carp qw(croak);
7 use CGI::Session::Driver;
8  
9 @CGI::Session::Driver::aggregator::ISA = ( "CGI::Session::Driver" );
10 $CGI::Session::Driver::aggregator::VERSION = "0.03";
11  
12 sub drivers {
13 my $self = shift;
14 return @{ $self->{drivers} };
15 }
16  
17 sub init {
18 my $self = shift;
19 unless (defined $self->{Drivers}) {
20 return $self->set_error("init(): 'Drivers' attribute is required.");
21 }
22  
23 my @drivers;
24 $self->{drivers} ||= [];
25 for my $d ( $self->{Drivers}->drivers ) {
26 my $obj = $d->{package}->new($d->{args});
27 push @drivers, $obj;
28 }
29  
30 $self->{drivers} = \@drivers;
31  
32 return 1;
33 }
34  
35 sub retrieve {
36 my $self = shift;
37 my ($sid) = @_;
38 croak "retrieve(): usage error" unless $sid;
39  
40 for my $driver ($self->drivers) {
41 if (my $data = $driver->retrieve(@_)) {
42 return $data;
43 }
44 }
45  
46 return 0;
47 }
48  
49 sub store {
50 my $self = shift;
51 my ($sid, $datastr) = @_;
52 croak "store(): usage error" unless $sid && $datastr;
53  
54 for my $driver (reverse $self->drivers) {
55 $driver->store(@_);
56 }
57  
58 return 1;
59 }
60  
61 sub remove {
62 my $self = shift;
63 my ($sid) = @_;
64 croak "remove(): usage error" unless $sid;
65  
66 for my $driver (reverse $self->drivers) {
67 $driver->remove(@_);
68 }
69
70 return 1;
71 }
72  
73  
74 sub DESTROY {
75 my $self = shift;
76 }
77  
78 sub traverse {
79 my $self = shift;
80 my ($coderef) = @_;
81  
82 unless ( $coderef && ref( $coderef ) && (ref $coderef eq 'CODE') ) {
83 croak "traverse(): usage error";
84 }
85  
86 for my $driver ($self->drivers) {
87 $driver->traverse(@_);
88 }
89  
90 return 1;
91 }
92  
93 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