blib/lib/CGI/Session/Driver/dbic.pm

filter: Statementstmt 40.7% 11 / 27 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 37.5% 3 / 8 Podpod 100% 5 / 5 totaltotal 41.3% 19 / 46 CC 4 SCAR 13.6
CC
4
Cov
33%
init
6.0
retrieve
6.0
traverse
6.0
CRAP 3.9
↑ Summary
1 package CGI::Session::Driver::dbic;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use base 'CGI::Session::Driver';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 CGI::Session::Driver::dbic - L<DBIx::Class> storage driver for L<CGI::Session>.
11  
12 =head1 VERSION
13  
14 Version 1.01
15  
16 =cut
17  
18 1 our $VERSION = '1.01';
19  
20 =head1 SYNOPSIS
21  
22 use CGI::Session;
23  
24 my $schema = MyDB::Schema->connect($dbi_dsn, $user, $pass, \%dbi_params);
25 my $dbic_rs = $schema->resultset('sessions');
26  
27 my $s = CGI::Session->new("driver:dbic", undef, {ResultSet => $dbic_rs});
28 ...
29  
30 =cut
31  
32 0 ▶sub init {
Subroutine init: not called CC=2 SCAR=17.9
Pod documented
33 0 my $self = shift;
34 return $self->set_error('init(): ResultSet param not set')
35 0 ▶ unless $self->{ResultSet};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"ResultSet"} 0 0 0
36 0 return 1;
37 }
38  
39 0 ▶sub store {
Subroutine store: not called CC=1 SCAR=6.9
Pod documented
40 0 my ($self, $sid, $datastr) = @_;
41 # Store $datastr, which is an already serialized string of data.
42 my $row = $self->{ResultSet}->update_or_create({
43 0 id => $sid,
44 a_session => $datastr,
45 });
46 0 return !(!$row);
47 }
48  
49 0 ▶sub retrieve {
Subroutine retrieve: not called CC=2 SCAR=17.9
Pod documented
50 0 my ($self, $sid) = @_;
51 # Return $datastr, which was previously stored using above store() method.
52 # Return $datastr if $sid was found. Return 0 or "" if $sid doesn't exist
53 0 my $row = $self->{ResultSet}->find($sid);
54 0 ▶ return $row ? $row->a_session : '';
Branch: 1 branch
BranchTrueFalseTotal
$row ? : 0 0 0
55 }
56  
57 0 ▶sub remove {
Subroutine remove: not called CC=1 SCAR=6.9
Pod documented
58 0 my ($self, $sid) = @_;
59 # Remove storage associated with $sid. Return any true value indicating success,
60 # or undef on failure.
61 0 return $self->{ResultSet}->search({id => $sid})->delete;
62 }
63  
64 0 ▶sub traverse {
Subroutine traverse: not called CC=2 SCAR=17.9
Pod documented
65 0 my ($self, $coderef) = @_;
66 # execute $coderef for each session id passing session id as the first and the only
67 # argument
68 0 my $rs = $self->{ResultSet}->search->get_column('id');
69 0 ▶ while (my $sid = $rs->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sid = $rs->next) 0 0 0
70 0 $coderef->($sid);
71 }
72 0 return 1;
73 }
74  
75 =head1 STORAGE
76  
77 The structure of the table is the same as in L<CGI::Session::Driver::DBI>.
78  
79 CREATE TABLE sessions (
80 id CHAR(32) NOT NULL PRIMARY KEY,
81 a_session TEXT NOT NULL
82 );
83  
84 DBIx::Class schema:
85  
86 package MyProject::DB::Session;
87 use base qw/DBIx::Class/;
88  
89 __PACKAGE__->load_components(qw/Core/);
90 __PACKAGE__->table('sessions');
91 __PACKAGE__->add_columns(
92 id => { data_type => 'char', size => 32 },
93 a_session => { data_type => 'bytea' },
94 );
95 __PACKAGE__->set_primary_key('id');
96  
97 1;
98  
99 =head1 DRIVER ARGUMENTS
100  
101 Following driver arguments are supported:
102  
103 =over 4
104  
105 =item ResultSet
106  
107 L<DBIx::Class::ResultSet> for sessions table.
108  
109 =back
110  
111 =head1 AUTHOR
112  
113 Sergey Homenkow, C<< <shomenkow at gmail.com> >>
114  
115 =head1 BUGS
116  
117 Please report any bugs or feature requests to C<bug-cgi-session-driver-dbic at rt.cpan.org>, or through
118 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CGI-Session-Driver-dbic>. I will be notified, and then you'll
119 automatically be notified of progress on your bug as I make changes.
120  
121 =head1 SUPPORT
122  
123 You can find documentation for this module with the perldoc command.
124  
125 perldoc CGI::Session::Driver::dbic
126  
127  
128 You can also look for information at:
129  
130 =over 4
131  
132 =item * RT: CPAN's request tracker
133  
134 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=CGI-Session-Driver-dbic>
135  
136 =item * AnnoCPAN: Annotated CPAN documentation
137  
138 L<http://annocpan.org/dist/CGI-Session-Driver-dbic>
139  
140 =item * CPAN Ratings
141  
142 L<http://cpanratings.perl.org/d/CGI-Session-Driver-dbic>
143  
144 =item * Search CPAN
145  
146 L<http://search.cpan.org/dist/CGI-Session-Driver-dbic/>
147  
148 =back
149  
150  
151 =head1 ACKNOWLEDGEMENTS
152  
153  
154 =head1 LICENSE AND COPYRIGHT
155  
156 Copyright 2010 Sergey Homenkow.
157  
158 This program is free software; you can redistribute it and/or modify it
159 under the terms of either: the GNU General Public License as published
160 by the Free Software Foundation; or the Artistic License.
161  
162 See http://dev.perl.org/licenses/ for more information.
163  
164  
165 =cut
166  
167 1 1; # End of CGI::Session::Driver::dbic
↑ Summary