| 1 | package CGI::Session::Driver::file; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | # $Id: file.pm 216 2005-09-01 10:52:26Z sherzodr $ | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 14 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 14 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 14 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 14 | ▶ | use Fcntl qw( :DEFAULT :flock :mode ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 14 | ▶ | use CGI::Session::Driver; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 14 | ▶ | use vars qw( $FileName); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 14 | @CGI::Session::Driver::file::ISA = ( "CGI::Session::Driver" ); | |||||||||||||||||||||||||||||||||||||||||
| 14 | 14 | $CGI::Session::Driver::file::VERSION = "3.4"; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 14 | $FileName = "cgisess_%s"; | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | sub init { | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | $self->{Directory} ||= File::Spec->tmpdir(); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"Directory"} ||= "File::Spec"->tmpdir
MC/DC0%0/2
$self->{"Directory"} ||= "File::Spec"->tmpdir
$self->{"Directory"}
"File::Spec"->tmpdir
Truth table0%0/3
A ||= B
A= $self->{"Directory"}B= "File::Spec"->tmpdir
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | if (defined $CGI::Session::File::FileName) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | $FileName = $CGI::Session::File::FileName; | |||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | unless ( -d $self->{Directory} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | require File::Path; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | unless ( File::Path::mkpath($self->{Directory}) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | return $self->set_error( "init(): couldn't create directory path: $!" ); | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | sub retrieve { | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
retrieve: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | my ($sid) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | my $directory = $self->{Directory}; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | my $file = sprintf( $FileName, $sid ); | |||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | my $path = File::Spec->catfile($directory, $file); | |||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | return 0 unless -e $path; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | unless ( sysopen(FH, $path, O_RDONLY) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | return $self->set_error( "retrieve(): couldn't open '$path': $!" ); | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | my $rv = ""; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | while ( <FH> ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | $rv .= $_; | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | close(FH); | |||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | return $rv; | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | sub store { | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
store: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | my ($sid, $datastr) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my $directory = $self->{Directory}; | |||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | my $file = sprintf( $FileName, $sid ); | |||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my $path = File::Spec->catfile($directory, $file); | |||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | sysopen(FH, $path, O_WRONLY|O_CREAT) or return $self->set_error( "store(): couldn't open '$path': $!" ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | flock(FH, LOCK_EX) or return $self->set_error( "store(): couldn't lock '$path': $!" ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | truncate(FH, 0) or return $self->set_error( "store(): couldn't truncate '$path': $!" ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | print FH $datastr; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | close(FH) or return $self->set_error( "store(): couldn't close '$path': $!" ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | sub remove { | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remove: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | my ($sid) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | my $directory = $self->{Directory}; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my $file = sprintf( $FileName, $sid ); | |||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | my $path = File::Spec->catfile($directory, $file); | |||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | unlink($path) or return $self->set_error( "remove(): couldn't unlink '$path': $!" ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | sub traverse { | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
traverse: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | my ($coderef) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | unless ( $coderef && ref($coderef) && (ref $coderef eq 'CODE') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$coderef and ref $coderef and ref $coderef eq "CODE"
$coderef and ref $coderef
MC/DC0%0/3
$coderef and ref $coderef and ref $coderef eq "CODE"
$coderef
ref $coderef
ref $coderef eq "CODE"
Truth table0%0/4
A and B and C
A= $coderefB= ref $coderefC= ref $coderef eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | croak "traverse(): usage error"; | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | opendir( DIRHANDLE, $self->{Directory} ) | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | or return $self->set_error( "traverse(): couldn't open $self->{Directory}, " . $! ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | my $filename_pattern = $FileName; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | $filename_pattern =~ s/\./\\./g; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | $filename_pattern =~ s/\%s/(\.\+)/g; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | while ( my $filename = readdir(DIRHANDLE) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | next if $filename =~ m/^\.\.?$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | my $full_path = File::Spec->catfile($self->{Directory}, $filename); | |||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | my $mode = (stat($full_path))[2] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | or return $self->set_error( "traverse(): stat failed for $full_path: " . $! ); | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | next if S_ISDIR($mode); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if ( $filename =~ /^$filename_pattern$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | $coderef->($1); | |||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | closedir( DIRHANDLE ); | |||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 14 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | __END__; | ||||||||||||||||||||||||||||||||||||||||||