| 1 | package WWW::Session::Storage::File; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | =head1 NAME | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | WWW::Session::Storage::File - File storage engine for WWW::Session | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | File backend for WWWW::Session | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | =head1 VERSION | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | Version 0.12 | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =cut | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 6 | our $VERSION = '0.12'; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | This module is used for storring serialized WWW::Session objects | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | Usage : | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | use WWW::Session::Storage::File; | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | my $storage = WWW::Session::Storage::File->new({path => '/tmp/sessions'}); | ||||||||||||||||||||||||||||
| 33 | ... | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | $storage->save($session_id,$expires,$serialized_data); | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | my $serialized_data = $storage->retrive($session_id); | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =head1 SUBROUTINES/METHODS | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =head2 new | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | Creates a new WWW::Session::Storage::File object | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | This method accepts only one argument, a hashref that must contain a key named | ||||||||||||||||||||||||||||
| 47 | "path" which defines the path where the sessions will be saved | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | =cut | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 4 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | 4 | my ($class,$params) = @_; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 4 | ▶ | die "You must specify the path where to save the sessions!" unless defined $params->{path}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 4 | ▶ | die "Cannot save sessions in folder '".$params->{path}."' because the folder does not exist!" unless -d $params->{path}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | my $self = { | ||||||||||||||||||||||||||||
| 59 | path => $params->{path} | ||||||||||||||||||||||||||||
| 60 | 4 | }; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 4 | bless $self, $class; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 4 | return $self; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | =head2 save | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | Stores the given information into the file | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | =cut | ||||||||||||||||||||||||||||
| 72 | 23 | ▶ | sub save { | ||||||||||||||||||||||||||
|
Subroutine
save: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | 23 | my ($self,$sid,$expires,$string) = @_; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 23 | open(my $fh,">",$self->{path}."/".$sid); | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 23 | print $fh $expires . "\n"; | |||||||||||||||||||||||||||
| 78 | 23 | print $fh $string; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 23 | close($fh); | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =head2 retrieve | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | Retrieves the informations for a session, verifies that it's not expired and returns | ||||||||||||||||||||||||||||
| 86 | the string containing the serialized data | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | =cut | ||||||||||||||||||||||||||||
| 89 | 12 | ▶ | sub retrieve { | ||||||||||||||||||||||||||
|
Subroutine
retrieve: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 90 | 12 | my ($self,$sid) = @_; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 12 | my $filename = $self->{path}."/".$sid; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 12 | ▶ | return undef unless -f $filename; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 9 | my @file_info = stat($filename); | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 9 | ▶ | open(my $fh,"<",$self->{path}."/".$sid) || return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 9 | local $/ = "\n"; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 9 | my $expires= readline($fh); | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 9 | local $/ = undef; | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 9 | my $string = readline($fh); | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 9 | close($fh); | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | #check if it didn't expire | ||||||||||||||||||||||||||||
| 111 | 9 | ▶ | if ($expires != -1 && ($file_info[8] + $expires) < time() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$expires != -1 and $file_info[8] + $expires < time
MC/DC100%2/2
$expires != -1 and $file_info[8] + $expires < time
$expires != -1
$file_info[8] + $expires < time
Truth table100%3/3
A and B
A= $expires != -1B= $file_info[8] + $expires < time
| |||||||||||||||||||||||||||||
| 112 | 1 | unlink $filename; | |||||||||||||||||||||||||||
| 113 | 1 | return undef; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 8 | return $string; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | =head2 delete | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | Completely removes the session data for the given session id | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | =cut | ||||||||||||||||||||||||||||
| 124 | 20 | ▶ | sub delete { | ||||||||||||||||||||||||||
|
Subroutine
delete: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 125 | 20 | my ($self,$sid) = @_; | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 20 | my $filename = $self->{path}."/".$sid; | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 20 | ▶ | if (-f $filename) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 20 | unlink($filename); | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | Gligan Calin Horea, C<< <gliganh at gmail.com> >> | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | =head1 BUGS | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | Please report any bugs or feature requests to C<bug-www-session at rt.cpan.org>, or through | ||||||||||||||||||||||||||||
| 141 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Session>. I will be notified, and then you'll | ||||||||||||||||||||||||||||
| 142 | automatically be notified of progress on your bug as I make changes. | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | perldoc WWW::Session::Storage::File | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | You can also look for information at: | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | =over 4 | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | =item * RT: CPAN's request tracker (report bugs here) | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=WWW-Session> | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | L<http://annocpan.org/dist/WWW-Session> | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | =item * CPAN Ratings | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | L<http://cpanratings.perl.org/d/WWW-Session> | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | =item * Search CPAN | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | L<http://search.cpan.org/dist/WWW-Session/> | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | =back | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | Copyright 2012 Gligan Calin Horea. | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 185 | under the terms of either: the GNU General Public License as published | ||||||||||||||||||||||||||||
| 186 | by the Free Software Foundation; or the Artistic License. | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | See http://dev.perl.org/licenses/ for more information. | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | =cut | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 6 | 1; # End of WWW::Session::Storage::File | |||||||||||||||||||||||||||