| 1 | package WWW::Session::Storage::Memcached; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use 5.006; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 1 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.9
| |||||||||||
| 8 | 0 | ▶ | eval "use Cache::Memcached;"; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
| |||||||||||
| 9 | |||||||||||
| 10 | 1 | ▶ | if ($@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 11 | 1 | warn "You must install Cache::Memcached module from CPAN to use the memcached storage engine!" | |||||||||
| 12 | } | ||||||||||
| 13 | } | ||||||||||
| 14 | |||||||||||
| 15 | |||||||||||
| 16 | =head1 NAME | ||||||||||
| 17 | |||||||||||
| 18 | WWW::Session::Storage::Memcached - Memcached storage for WWW::Session | ||||||||||
| 19 | |||||||||||
| 20 | =head1 DESCRIPTION | ||||||||||
| 21 | |||||||||||
| 22 | Memcached backend for WWW::Session | ||||||||||
| 23 | |||||||||||
| 24 | =head1 VERSION | ||||||||||
| 25 | |||||||||||
| 26 | Version 0.12 | ||||||||||
| 27 | |||||||||||
| 28 | =cut | ||||||||||
| 29 | |||||||||||
| 30 | 1 | our $VERSION = '0.12'; | |||||||||
| 31 | |||||||||||
| 32 | |||||||||||
| 33 | =head1 SYNOPSIS | ||||||||||
| 34 | |||||||||||
| 35 | This module is used for storring serialized WWW::Session objects in memcached | ||||||||||
| 36 | |||||||||||
| 37 | Usage : | ||||||||||
| 38 | |||||||||||
| 39 | use WWW::Session::Storage::Memcached; | ||||||||||
| 40 | |||||||||||
| 41 | my $storage = WWW::Session::Storage::Memcached->new({ servers => ["127.0.0.1:11211"] }); | ||||||||||
| 42 | ... | ||||||||||
| 43 | |||||||||||
| 44 | $storage->save($session_id,$expires,$serialized_data); | ||||||||||
| 45 | |||||||||||
| 46 | my $serialized_data = $storage->retrive($session_id); | ||||||||||
| 47 | |||||||||||
| 48 | =head1 SUBROUTINES/METHODS | ||||||||||
| 49 | |||||||||||
| 50 | =head2 new | ||||||||||
| 51 | |||||||||||
| 52 | Creates a new WWW::Session::Storage::File object | ||||||||||
| 53 | |||||||||||
| 54 | This method accepts only one argument, a hashref that contains all the options that will be | ||||||||||
| 55 | passed to the Cache::Memcached module. The mendatory key in the hash is "servers" wihich must | ||||||||||
| 56 | be an array ref containing all the C<memcached> servers we want to use. | ||||||||||
| 57 | |||||||||||
| 58 | See Cache::Memcached module for more details on available options | ||||||||||
| 59 | |||||||||||
| 60 | Example : | ||||||||||
| 61 | |||||||||||
| 62 | my $storage = WWW::Session::Storage::Memcached->new({ servers => ["127.0.0.1:11211"] }); | ||||||||||
| 63 | |||||||||||
| 64 | =cut | ||||||||||
| 65 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 66 | 0 | my $class = shift; | |||||||||
| 67 | 0 | my $params = shift; | |||||||||
| 68 | |||||||||||
| 69 | 0 | my $self = { options => $params, | |||||||||
| 70 | memcached => Cache::Memcached->new($params), | ||||||||||
| 71 | }; | ||||||||||
| 72 | |||||||||||
| 73 | 0 | bless $self, $class; | |||||||||
| 74 | |||||||||||
| 75 | 0 | return $self; | |||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | =head2 save | ||||||||||
| 79 | |||||||||||
| 80 | Stores the given information into the file | ||||||||||
| 81 | |||||||||||
| 82 | =cut | ||||||||||
| 83 | 0 | ▶ | sub save { | ||||||||
|
Subroutine
save: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 84 | 0 | my ($self,$sid,$expires,$string) = @_; | |||||||||
| 85 | |||||||||||
| 86 | 0 | ▶ | return $self->{memcached}->set($sid,$string,$expires == -1 ? undef : $expires ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | =head2 retrieve | ||||||||||
| 90 | |||||||||||
| 91 | Retrieves the informations for a session, verifies that it's not expired and returns | ||||||||||
| 92 | the string containing the serialized data | ||||||||||
| 93 | |||||||||||
| 94 | =cut | ||||||||||
| 95 | 0 | ▶ | sub retrieve { | ||||||||
|
Subroutine
retrieve: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 96 | 0 | my ($self,$sid) = @_; | |||||||||
| 97 | |||||||||||
| 98 | 0 | return $self->{memcached}->get($sid); | |||||||||
| 99 | } | ||||||||||
| 100 | |||||||||||
| 101 | =head2 delete | ||||||||||
| 102 | |||||||||||
| 103 | Completely removes the session data for the given session id | ||||||||||
| 104 | |||||||||||
| 105 | =cut | ||||||||||
| 106 | 0 | ▶ | sub delete { | ||||||||
|
Subroutine
delete: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 107 | 0 | my ($self,$sid) = @_; | |||||||||
| 108 | |||||||||||
| 109 | 0 | $self->{memcached}->delete($sid); | |||||||||
| 110 | } | ||||||||||
| 111 | |||||||||||
| 112 | =head1 AUTHOR | ||||||||||
| 113 | |||||||||||
| 114 | Gligan Calin Horea, C<< <gliganh at gmail.com> >> | ||||||||||
| 115 | |||||||||||
| 116 | =head1 BUGS | ||||||||||
| 117 | |||||||||||
| 118 | Please report any bugs or feature requests to C<bug-www-session at rt.cpan.org>, or through | ||||||||||
| 119 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Session>. I will be notified, and then you'll | ||||||||||
| 120 | automatically be notified of progress on your bug as I make changes. | ||||||||||
| 121 | |||||||||||
| 122 | |||||||||||
| 123 | |||||||||||
| 124 | |||||||||||
| 125 | =head1 SUPPORT | ||||||||||
| 126 | |||||||||||
| 127 | You can find documentation for this module with the perldoc command. | ||||||||||
| 128 | |||||||||||
| 129 | perldoc WWW::Session::Storage::Memcached | ||||||||||
| 130 | |||||||||||
| 131 | |||||||||||
| 132 | You can also look for information at: | ||||||||||
| 133 | |||||||||||
| 134 | =over 4 | ||||||||||
| 135 | |||||||||||
| 136 | =item * RT: CPAN's request tracker (report bugs here) | ||||||||||
| 137 | |||||||||||
| 138 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=WWW-Session> | ||||||||||
| 139 | |||||||||||
| 140 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 141 | |||||||||||
| 142 | L<http://annocpan.org/dist/WWW-Session> | ||||||||||
| 143 | |||||||||||
| 144 | =item * CPAN Ratings | ||||||||||
| 145 | |||||||||||
| 146 | L<http://cpanratings.perl.org/d/WWW-Session> | ||||||||||
| 147 | |||||||||||
| 148 | =item * Search CPAN | ||||||||||
| 149 | |||||||||||
| 150 | L<http://search.cpan.org/dist/WWW-Session/> | ||||||||||
| 151 | |||||||||||
| 152 | =back | ||||||||||
| 153 | |||||||||||
| 154 | |||||||||||
| 155 | =head1 ACKNOWLEDGEMENTS | ||||||||||
| 156 | |||||||||||
| 157 | |||||||||||
| 158 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 159 | |||||||||||
| 160 | Copyright 2012 Gligan Calin Horea. | ||||||||||
| 161 | |||||||||||
| 162 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 163 | under the terms of either: the GNU General Public License as published | ||||||||||
| 164 | by the Free Software Foundation; or the Artistic License. | ||||||||||
| 165 | |||||||||||
| 166 | See http://dev.perl.org/licenses/ for more information. | ||||||||||
| 167 | |||||||||||
| 168 | |||||||||||
| 169 | =cut | ||||||||||
| 170 | |||||||||||
| 171 | 1 | 1; # End of WWW::Session::Storage::Memcached | |||||||||