Session/Driver/file.pm

filter: Statementstmt 27.8% 22 / 79 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 50.0% 6 / 12 Podpod 100% 5 / 5 totaltotal 22.6% 33 / 146 SCAR 56.7
CC
22
Cov
18%
traverse
110.0
init
30.0
store
30.0
CRAP 291.4
« Session/Driver/DBI.pm ↑ Summary Session/Serialize/default.pm »
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
l!l&&r!l&&!r
000
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
ABresult
1X1
011
000
20  
21 0 ▶ if (defined $CGI::Session::File::FileName) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $CGI::Session::File::FileName) 0 0 0
22 0 $FileName = $CGI::Session::File::FileName;
23 }
24  
25 0 ▶ unless ( -d $self->{Directory} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $self->{"Directory"}) 0 0 0
26 0 require File::Path;
27 0 ▶ unless ( File::Path::mkpath($self->{Directory}) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (File::Path::mkpath($self->{"Directory"})) 0 0 0
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
BranchTrueFalseTotal
unless -e $path 0 0 0
42  
43 0 ▶ unless ( sysopen(FH, $path, O_RDONLY) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (sysopen FH, $path, 0) 0 0 0
44 0 return $self->set_error( "retrieve(): couldn't open '$path': $!" );
45 }
46 0 my $rv = "";
47 0 ▶ while ( <FH> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline FH)) 0 0 0
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
BranchTrueFalseTotal
sysopen FH, $path, 65 or return $self->set_error("store(): couldn't open '${path}': $!") 0 0 0
64 0 ▶ flock(FH, LOCK_EX) or return $self->set_error( "store(): couldn't lock '$path': $!" );
Branch: 1 branch
BranchTrueFalseTotal
flock FH, 2 or return $self->set_error("store(): couldn't lock '${path}': $!") 0 0 0
65 0 ▶ truncate(FH, 0) or return $self->set_error( "store(): couldn't truncate '$path': $!" );
Branch: 1 branch
BranchTrueFalseTotal
truncate FH, 0 or return $self->set_error("store(): couldn't truncate '${path}': $!") 0 0 0
66 0 print FH $datastr;
67 0 ▶ close(FH) or return $self->set_error( "store(): couldn't close '$path': $!" );
Branch: 1 branch
BranchTrueFalseTotal
close FH or return $self->set_error("store(): couldn't close '${path}': $!") 0 0 0
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
BranchTrueFalseTotal
unlink $path or return $self->set_error("remove(): couldn't unlink '${path}': $!") 0 0 0
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
BranchTrueFalseTotal
unless ($coderef and ref $coderef and ref $coderef eq "CODE") 0 0 0
Condition0%0/6
$coderef and ref $coderef and ref $coderef eq "CODE"
!ll&&!rl&&r
000
$coderef and ref $coderef
!ll&&!rl&&r
000
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"
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
opendir DIRHANDLE, $self->{"Directory"} or return $self->set_error(qq[traverse(): couldn't open $self->{"Directory"}, ] . $!) 0 0 0
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
BranchTrueFalseTotal
if (defined(my $filename = readdir DIRHANDLE)) 0 0 0
99 0 ▶ next if $filename =~ m/^\.\.?$/;
Branch: 1 branch
BranchTrueFalseTotal
if $filename =~ /^\.\.?$/ 0 0 0
100 0 my $full_path = File::Spec->catfile($self->{Directory}, $filename);
101 0 ▶ my $mode = (stat($full_path))[2]
Branch: 1 branch
BranchTrueFalseTotal
my $mode = (stat $full_path)[2] or return $self->set_error("traverse(): stat failed for ${full_path}: " . $!) 0 0 0
102 or return $self->set_error( "traverse(): stat failed for $full_path: " . $! );
103 0 ▶ next if S_ISDIR($mode);
Branch: 1 branch
BranchTrueFalseTotal
if S_ISDIR($mode) 0 0 0
104 0 ▶ if ( $filename =~ /^$filename_pattern$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filename =~ /^$filename_pattern$/) 0 0 0
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__;
« Session/Driver/DBI.pm ↑ Summary Session/Serialize/default.pm »