| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package WWW::Session::Storage::File; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 4 |  |  | 4 |  | 2081 | use 5.006; | 
|  | 4 |  |  |  |  | 15 |  | 
|  | 4 |  |  |  |  | 168 |  | 
| 4 | 4 |  |  | 4 |  | 24 | use strict; | 
|  | 4 |  |  |  |  | 8 |  | 
|  | 4 |  |  |  |  | 129 |  | 
| 5 | 4 |  |  | 4 |  | 23 | use warnings; | 
|  | 4 |  |  |  |  | 7 |  | 
|  | 4 |  |  |  |  | 1994 |  | 
| 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.10 | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | =cut | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | our $VERSION = '0.10'; | 
| 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 |  |  |  |  |  |  | sub new { | 
| 52 | 3 |  |  | 3 | 1 | 774 | my ($class,$params) = @_; | 
| 53 |  |  |  |  |  |  |  | 
| 54 | 3 | 50 |  |  |  | 14 | die "You must specify the path where to save the sessions!" unless defined $params->{path}; | 
| 55 |  |  |  |  |  |  |  | 
| 56 | 3 | 50 |  |  |  | 52 | die "Cannot save sessions in folder '".$params->{path}."' because the folder does not exist!" unless -d $params->{path}; | 
| 57 |  |  |  |  |  |  |  | 
| 58 | 3 |  |  |  |  | 9 | my $self = { | 
| 59 |  |  |  |  |  |  | path => $params->{path} | 
| 60 |  |  |  |  |  |  | }; | 
| 61 |  |  |  |  |  |  |  | 
| 62 | 3 |  |  |  |  | 11 | bless $self, $class; | 
| 63 |  |  |  |  |  |  |  | 
| 64 | 3 |  |  |  |  | 10 | return $self; | 
| 65 |  |  |  |  |  |  | } | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | =head2 save | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | Stores the given information into the file | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | =cut | 
| 72 |  |  |  |  |  |  | sub save { | 
| 73 | 19 |  |  | 19 | 1 | 3923 | my ($self,$sid,$expires,$string) = @_; | 
| 74 |  |  |  |  |  |  |  | 
| 75 | 19 |  |  |  |  | 2588 | open(my $fh,">",$self->{path}."/".$sid); | 
| 76 |  |  |  |  |  |  |  | 
| 77 | 19 |  |  |  |  | 170 | print $fh $expires . "\n"; | 
| 78 | 19 |  |  |  |  | 64 | print $fh $string; | 
| 79 |  |  |  |  |  |  |  | 
| 80 | 19 |  |  |  |  | 1473 | 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 |  |  |  |  |  |  | sub retrieve { | 
| 90 | 12 |  |  | 12 | 1 | 40 | my ($self,$sid) = @_; | 
| 91 |  |  |  |  |  |  |  | 
| 92 | 12 |  |  |  |  | 99 | my $filename = $self->{path}."/".$sid; | 
| 93 |  |  |  |  |  |  |  | 
| 94 | 12 | 100 |  |  |  | 535 | return undef unless -f $filename; | 
| 95 |  |  |  |  |  |  |  | 
| 96 | 9 |  |  |  |  | 262 | my @file_info = stat($filename); | 
| 97 |  |  |  |  |  |  |  | 
| 98 | 9 | 50 |  |  |  | 1163 | open(my $fh,"<",$self->{path}."/".$sid) || return undef; | 
| 99 |  |  |  |  |  |  |  | 
| 100 | 9 |  |  |  |  | 205 | local $/ = "\n"; | 
| 101 |  |  |  |  |  |  |  | 
| 102 | 9 |  |  |  |  | 313 | my $expires= readline($fh); | 
| 103 |  |  |  |  |  |  |  | 
| 104 | 9 |  |  |  |  | 46 | local $/ = undef; | 
| 105 |  |  |  |  |  |  |  | 
| 106 | 9 |  |  |  |  | 252 | my $string = readline($fh); | 
| 107 |  |  |  |  |  |  |  | 
| 108 | 9 |  |  |  |  | 271 | close($fh); | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | #check if it didn't expire | 
| 111 | 9 | 100 | 100 |  |  | 254 | if ($expires != -1 && ($file_info[8] + $expires) < time() ) { | 
| 112 | 1 |  |  |  |  | 227 | unlink $filename; | 
| 113 | 1 |  |  |  |  | 23 | return undef; | 
| 114 |  |  |  |  |  |  | } | 
| 115 |  |  |  |  |  |  |  | 
| 116 | 8 |  |  |  |  | 169 | return $string; | 
| 117 |  |  |  |  |  |  | } | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | =head2 delete | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | Completely removes the session data for the given session id | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | =cut | 
| 124 |  |  |  |  |  |  | sub delete { | 
| 125 | 16 |  |  | 16 | 1 | 19386 | my ($self,$sid) = @_; | 
| 126 |  |  |  |  |  |  |  | 
| 127 | 16 |  |  |  |  | 55 | my $filename = $self->{path}."/".$sid; | 
| 128 |  |  |  |  |  |  |  | 
| 129 | 16 | 50 |  |  |  | 338 | if (-f $filename) { | 
| 130 | 16 |  |  |  |  | 1543 | unlink($filename); | 
| 131 |  |  |  |  |  |  | } | 
| 132 |  |  |  |  |  |  | } | 
| 133 |  |  |  |  |  |  |  | 
| 134 |  |  |  |  |  |  | =head1 AUTHOR | 
| 135 |  |  |  |  |  |  |  | 
| 136 |  |  |  |  |  |  | Gligan Calin Horea, C<<  >> | 
| 137 |  |  |  |  |  |  |  | 
| 138 |  |  |  |  |  |  | =head1 BUGS | 
| 139 |  |  |  |  |  |  |  | 
| 140 |  |  |  |  |  |  | Please report any bugs or feature requests to C, or through | 
| 141 |  |  |  |  |  |  | the web interface at L.  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 | 
| 161 |  |  |  |  |  |  |  | 
| 162 |  |  |  |  |  |  | =item * AnnoCPAN: Annotated CPAN documentation | 
| 163 |  |  |  |  |  |  |  | 
| 164 |  |  |  |  |  |  | L | 
| 165 |  |  |  |  |  |  |  | 
| 166 |  |  |  |  |  |  | =item * CPAN Ratings | 
| 167 |  |  |  |  |  |  |  | 
| 168 |  |  |  |  |  |  | L | 
| 169 |  |  |  |  |  |  |  | 
| 170 |  |  |  |  |  |  | =item * Search CPAN | 
| 171 |  |  |  |  |  |  |  | 
| 172 |  |  |  |  |  |  | L | 
| 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 |  |  |  |  |  |  | 1; # End of WWW::Session::Storage::File |